jax ws - WCF Web服务,Java Web客户端,MustUnderstand标头不理解



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

<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)

Running:

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

使用寻址模块,修复此问题。

我知道这篇文章是旧的,但可能有人仍然面临这个问题。

我正在使用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());

还添加寻址。Mar和soapmonitor。

我也有同样的问题。

在我的例子中,web服务的WSDL是使用。net中的WCF创建的,我们在JAVA端使用它。经过几次尝试后,我注意到web服务中缺少相应的标头。我要求我的。net团队在web服务中添加一个端口名称。该端口名称只是web服务中的普通名称。这是必需的,因为在JAVA端,我们需要端口类型和端口名称来实际访问web服务。

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

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

如果客户端已经使用Apache CXF生成并面临此问题,那么以下内容将有所帮助:

  1. 在IService接口中添加如下注释:@Addressing(enabled=true, required=false)

  2. 在客户端类中,用于获取用于调用的服务:

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

最新更新