WCF Web 服务、Java Web 客户端、MustUnderstand 标头不理解?

发布于 2024-11-24 04:23:07 字数 5192 浏览 3 评论 0原文

我正在托管具有以下 WSDL 的 WCF Web 服务(使用 wsHttpBinding 和 SSL 实现传输安全的简单服务):

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://tempuri.org/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" name="MagicEightBallService" targetNamespace="http://tempuri.org/">
  <wsp:Policy wsu:Id="WSHttpBinding_TransportSecurity_IMagicEightBallService_policy">
    <wsp:ExactlyOne>
      <wsp:All>
        <sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
          <wsp:Policy>
            <sp:TransportToken>
              <wsp:Policy>
                <sp:HttpsToken RequireClientCertificate="false"/>
              </wsp:Policy>
            </sp:TransportToken>
            <sp:AlgorithmSuite>
              <wsp:Policy>
                <sp:Basic256/>
              </wsp:Policy>
            </sp:AlgorithmSuite>
            <sp:Layout>
              <wsp:Policy>
                <sp:Strict/>
              </wsp:Policy>
            </sp:Layout>
          </wsp:Policy>
        </sp:TransportBinding>
        <wsaw:UsingAddressing/>
      </wsp:All>
    </wsp:ExactlyOne>
  </wsp:Policy>
  <wsdl:types>
    <xsd:schema targetNamespace="http://tempuri.org/Imports">
      <xsd:import schemaLocation="http://my.local.domain.name/MagicEightBall/MagicEightBallService.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
      <xsd:import schemaLocation="http://my.local.domain.name/MagicEightBall/MagicEightBallService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="IMagicEightBallService_GetAdvice_InputMessage">
    <wsdl:part name="parameters" element="tns:GetAdvice"/>
  </wsdl:message>
  <wsdl:message name="IMagicEightBallService_GetAdvice_OutputMessage">
    <wsdl:part name="parameters" element="tns:GetAdviceResponse"/>
  </wsdl:message>
  <wsdl:portType name="IMagicEightBallService">
    <wsdl:operation name="GetAdvice">
      <wsdl:input wsaw:Action="http://tempuri.org/IMagicEightBallService/GetAdvice" message="tns:IMagicEightBallService_GetAdvice_InputMessage"/>
      <wsdl:output wsaw:Action="http://tempuri.org/IMagicEightBallService/GetAdviceResponse" message="tns:IMagicEightBallService_GetAdvice_OutputMessage"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="WSHttpBinding_TransportSecurity_IMagicEightBallService" type="tns:IMagicEightBallService">
    <wsp:PolicyReference URI="#WSHttpBinding_TransportSecurity_IMagicEightBallService_policy"/>
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="GetAdvice">
      <soap12:operation soapAction="http://tempuri.org/IMagicEightBallService/GetAdvice" style="document"/>
      <wsdl:input>
        <soap12:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="MagicEightBallService">
    <wsdl:port name="WSHttpBinding_TransportSecurity_IMagicEightBallService" binding="tns:WSHttpBinding_TransportSecurity_IMagicEightBallService">
      <soap12:address location="https://localhost/MagicEightBall/MagicEightBallService.svc"/>
      <wsa10:EndpointReference>
        <wsa10:Address>
          https://localhost/MagicEightBall/MagicEightBallService.svc
        </wsa10:Address>
      </wsa10:EndpointReference>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

为什么当我尝试从 Java 使用此服务时会出现错误?当我尝试使用 Axis2/Java 来使用它时,我收到错误:

org.apache.axis2.AxisFault: Must Understand check failed for header http://www.w3.org/2005/08/addressing : Action

当我尝试使用 JAX-WS 时,我收到错误:

javax.xml.ws.soap.SOAPFaultException: MustUnderstand headers:[{http://www.w3.org/2005/08/addressing}Action] are not understood

到目前为止,我还没有成功使用其中任何一个,而且我没有确定是否需要对服务器或客户端应用修复。

(有关更多详细信息,请参阅我发布的相关问题,包括 WCF Web.config)。

I'm hosting a WCF Web Service with the following WSDL (a simple service using wsHttpBinding and SSL for transport security):

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://tempuri.org/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" name="MagicEightBallService" targetNamespace="http://tempuri.org/">
  <wsp:Policy wsu:Id="WSHttpBinding_TransportSecurity_IMagicEightBallService_policy">
    <wsp:ExactlyOne>
      <wsp:All>
        <sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
          <wsp:Policy>
            <sp:TransportToken>
              <wsp:Policy>
                <sp:HttpsToken RequireClientCertificate="false"/>
              </wsp:Policy>
            </sp:TransportToken>
            <sp:AlgorithmSuite>
              <wsp:Policy>
                <sp:Basic256/>
              </wsp:Policy>
            </sp:AlgorithmSuite>
            <sp:Layout>
              <wsp:Policy>
                <sp:Strict/>
              </wsp:Policy>
            </sp:Layout>
          </wsp:Policy>
        </sp:TransportBinding>
        <wsaw:UsingAddressing/>
      </wsp:All>
    </wsp:ExactlyOne>
  </wsp:Policy>
  <wsdl:types>
    <xsd:schema targetNamespace="http://tempuri.org/Imports">
      <xsd:import schemaLocation="http://my.local.domain.name/MagicEightBall/MagicEightBallService.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
      <xsd:import schemaLocation="http://my.local.domain.name/MagicEightBall/MagicEightBallService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="IMagicEightBallService_GetAdvice_InputMessage">
    <wsdl:part name="parameters" element="tns:GetAdvice"/>
  </wsdl:message>
  <wsdl:message name="IMagicEightBallService_GetAdvice_OutputMessage">
    <wsdl:part name="parameters" element="tns:GetAdviceResponse"/>
  </wsdl:message>
  <wsdl:portType name="IMagicEightBallService">
    <wsdl:operation name="GetAdvice">
      <wsdl:input wsaw:Action="http://tempuri.org/IMagicEightBallService/GetAdvice" message="tns:IMagicEightBallService_GetAdvice_InputMessage"/>
      <wsdl:output wsaw:Action="http://tempuri.org/IMagicEightBallService/GetAdviceResponse" message="tns:IMagicEightBallService_GetAdvice_OutputMessage"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="WSHttpBinding_TransportSecurity_IMagicEightBallService" type="tns:IMagicEightBallService">
    <wsp:PolicyReference URI="#WSHttpBinding_TransportSecurity_IMagicEightBallService_policy"/>
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="GetAdvice">
      <soap12:operation soapAction="http://tempuri.org/IMagicEightBallService/GetAdvice" style="document"/>
      <wsdl:input>
        <soap12:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="MagicEightBallService">
    <wsdl:port name="WSHttpBinding_TransportSecurity_IMagicEightBallService" binding="tns:WSHttpBinding_TransportSecurity_IMagicEightBallService">
      <soap12:address location="https://localhost/MagicEightBall/MagicEightBallService.svc"/>
      <wsa10:EndpointReference>
        <wsa10:Address>
          https://localhost/MagicEightBall/MagicEightBallService.svc
        </wsa10:Address>
      </wsa10:EndpointReference>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

Why do I get errors when I try to consume this from Java? When I try to consume it using Axis2/Java, I get the error:

org.apache.axis2.AxisFault: Must Understand check failed for header http://www.w3.org/2005/08/addressing : Action

And when I try to use JAX-WS, I get the error:

javax.xml.ws.soap.SOAPFaultException: MustUnderstand headers:[{http://www.w3.org/2005/08/addressing}Action] are not understood

So far I haven't had any success with either of these, and I'm not sure whether a fix needs to be applied to the server or the client.

(See a related question I posted for more details, including the WCF Web.config).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

木落 2024-12-01 04:23:29

如果客户端是使用 Apache CXF 生成的并面临此问题,则以下内容会有所帮助:

  1. 将以下注释添加到 IService 接口:
    @Addressing(enabled=true, required=false)

  2. 在客户端类中,这是获取服务以进行调用的地方:

ServiceImpl service = new ServiceImpl(wsdl,service); IService port = service.getWSHttpBindingIService(new AddressingFeature(true));

AddressingFeature 的导入是 javax.xml.ws.soap.AddressingFeature;

If client has been generated using Apache CXF and facing this issue, then below helps:

  1. Add below annotation to IService interface:
    @Addressing(enabled=true, required=false)

  2. In client class that is where the service is being obtained for calling:

ServiceImpl service = new ServiceImpl(wsdl,service); IService port = service.getWSHttpBindingIService(new AddressingFeature(true));

Import for AddressingFeature is javax.xml.ws.soap.AddressingFeature;

流云如水 2024-12-01 04:23:28

还将addressing.mar 和soapmonitor.mar 添加到您的库路径中。

also add addressing.mar and soapmonitor.mar to your library path.

锦上情书 2024-12-01 04:23:28

我也有同样的问题。

就我而言,Web 服务的 WSDL 是使用 .net 中的 WCF 创建的,我们在 JAVA 端使用它。经过几次尝试后,我注意到网络服务中缺少相应的标头。我要求我的 dotnet 团队在 Web 服务中添加一个 - 端口名称。此端口名称只是 Web 服务中的普通名称。这是需要的,因为在 JAVA 端,我们需要端口类型和端口名称才能实际访问 Web 服务。

尝试在服务内的 .net 端添加以下行,然后尝试在 JAVA 端使用。

[ServiceContract(Namespace = "BookStockWebService", Name = "BookStock")]
[ServiceBehavior(Namespace = "BookStockWebServiceport", Name = "BookStockPort")]

I too had the same problem.

In my case the webservice's WSDL was created using WCF in .net and we are consuming it at JAVA side. After several tries I noticed that the corresponding header was missing in the web service. I asked my dotnet team to add a - port name in the webservice.This port name just a normal name in the web service. This was needed because at JAVA side we need port type and port name to actually access the webservice.

Try to add below lines at the .net side inside the service and then try to consume at JAVA side.

[ServiceContract(Namespace = "BookStockWebService", Name = "BookStock")]
[ServiceBehavior(Namespace = "BookStockWebServiceport", Name = "BookStockPort")]
半岛未凉 2024-12-01 04:23:27

我知道该帖子很旧,但有人可能仍然面临这个问题。

我正在使用 JAX-WS,并且遇到了同样的问题。阅读 https://jax-ws.java 后.net/jax-ws-21-ea3/docs/wsaddressing.html#On_the_client_side 我找到了一个适合我的解决方案。

代码在以下行中中断:

IFooService service = new FooService().getWSHttpBindingIFooService();

我所做的如下:

IFooService service = new FooService().getWSHttpBindingIFooService(new javax.xml.ws.soap.AddressingFeature());

就是这样。

I know the post is old, but someone may still face this problem.

I'm using JAX-WS, and I was having the same issue. After reading https://jax-ws.java.net/jax-ws-21-ea3/docs/wsaddressing.html#On_the_client_side I've found a solution that worked for me.

The code was breaking in the following line:

IFooService service = new FooService().getWSHttpBindingIFooService();

What I've done is the following:

IFooService service = new FooService().getWSHttpBindingIFooService(new javax.xml.ws.soap.AddressingFeature());

That's it.

烟雨凡馨 2024-12-01 04:23:25

运行:

ServiceClient sc = stub._getServiceClient();
sc.engageModule("addressing");

使用寻址模块,解决此问题。

Running:

ServiceClient sc = stub._getServiceClient();
sc.engageModule("addressing");

engages the Addressing module, fixing this issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文