0

我有一个用 JAX-WS 实现并部署在 JBossAS 7 上的 Web 服务存根。这是一个源代码:

package org.mycompany.adapters.ws;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.soap.Addressing;

@WebService
@Addressing(enabled = true, required = true)
public class AdapterSessionManager {

    @WebMethod
    public String initAdapterSession() {
        return "hello";
    }
}

这是 JBoss 为该 Web 服务生成的 WSDL:

<wsdl:definitions name="AdapterSessionManagerService" targetNamespace="http://ws.adapters.mycompany.org/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.adapters.mycompany.org/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <wsdl:types>
      <xs:schema elementFormDefault="unqualified" targetNamespace="http://ws.adapters.mycompany.org/" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
         <xs:element name="initAdapterSession" type="tns:initAdapterSession"/>
         <xs:element name="initAdapterSessionResponse" type="tns:initAdapterSessionResponse"/>
         <xs:complexType name="initAdapterSession">
            <xs:sequence/>
         </xs:complexType>
         <xs:complexType name="initAdapterSessionResponse">
            <xs:sequence>
               <xs:element minOccurs="0" name="return" type="xs:string"/>
            </xs:sequence>
         </xs:complexType>
      </xs:schema>
   </wsdl:types>
   <wsdl:message name="initAdapterSessionResponse">
      <wsdl:part element="tns:initAdapterSessionResponse" name="parameters"/>
   </wsdl:message>
   <wsdl:message name="initAdapterSession">
      <wsdl:part element="tns:initAdapterSession" name="parameters"/>
   </wsdl:message>
   <wsdl:portType name="AdapterSessionManager">
      <wsdl:operation name="initAdapterSession">
         <wsdl:input message="tns:initAdapterSession" name="initAdapterSession" wsam:Action="http://ws.adapters.mycompany.org/AdapterSessionManager/initAdapterSessionRequest" wsaw:Action="http://ws.adapters.mycompany.org/AdapterSessionManager/initAdapterSessionRequest"/>
         <wsdl:output message="tns:initAdapterSessionResponse" name="initAdapterSessionResponse" wsam:Action="http://ws.adapters.mycompany.org/AdapterSessionManager/initAdapterSessionResponse" wsaw:Action="http://ws.adapters.mycompany.org/AdapterSessionManager/initAdapterSessionResponse"/>
      </wsdl:operation>
   </wsdl:portType>
   <wsdl:binding name="AdapterSessionManagerServiceSoapBinding" type="tns:AdapterSessionManager">
      <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
      <wsaw:UsingAddressing wsdl:required="true"/>
      <wsp:PolicyReference URI="#AdapterSessionManagerServiceSoapBinding_WSAM_Addressing_Policy"/>
      <wsdl:operation name="initAdapterSession">
         <soap:operation soapAction="" style="document"/>
         <wsdl:input name="initAdapterSession">
            <soap:body use="literal"/>
         </wsdl:input>
         <wsdl:output name="initAdapterSessionResponse">
            <soap:body use="literal"/>
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="AdapterSessionManagerService">
      <wsdl:port binding="tns:AdapterSessionManagerServiceSoapBinding" name="AdapterSessionManagerPort">
         <soap:address location="http://localhost:8081/adapters/AdapterSessionManager"/>
      </wsdl:port>
   </wsdl:service>
   <wsp:Policy wsu:Id="AdapterSessionManagerServiceSoapBinding_WSAM_Addressing_Policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
      <wsam:Addressing>
         <wsp:Policy/>
      </wsam:Addressing>
   </wsp:Policy>
</wsdl:definitions>

当我尝试initAdapterSession使用以下 SOAP 请求调用时:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.adapters.mycompany.org/">
   <soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
      <wsa:Action>http://ws.adapters.mycompany.org/AdapterSessionManager/initAdapterSessionRequest</wsa:Action>
   </soapenv:Header>
   <soapenv:Body>
      <ws:initAdapterSession/>
   </soapenv:Body>
</soapenv:Envelope>

"A required header representing a Message Addressing Property is not present"出现 SOAP 错误:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header>
      <Action xmlns="http://www.w3.org/2005/08/addressing">http://ws.adapters.mycompany.org/AdapterSessionManager/initAdapterSession/Fault/SoapFault</Action>
      <MessageID xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:d5b5c6aa-fd66-49bd-b928-488fa8e07f7b</MessageID>
      <RelatesTo xmlns="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/unspecified</RelatesTo>
   </soap:Header>
   <soap:Body>
      <soap:Fault>
         <faultcode xmlns:ns1="http://www.w3.org/2005/08/addressing">ns1:MessageAddressingHeaderRequired</faultcode>
         <faultstring>A required header representing a Message Addressing Property is not present</faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

SOAP 请求由soapUI 发送。soapUI 首选项(WS-A settings选项卡)中的所有 WS-A 选项都被禁用。Enable WS-A addressing请求设置中的复选框也已关闭。实际上,即使启用了所有这些选项,也会发生相同的错误。

为什么 JBoss 在请求中看不到 WS-A 标头?

4

2 回答 2

1

"A required header representing a Message Addressing Property is not present"当 SOAP 消息没有所有必需的 WS-Addressing 标头信息时,就会发生SOAP 错误。这不是 JBoss 特定的例外,我在 WebSphere 上也遇到过这种情况。

您的请求仅表明它正在发送Action标头。查看规范(http://www.w3.org/Submission/ws-addressing/#_Toc77464323),您似乎需要同时发送ActionTo标头。另一种选择是根本不发送任何 WS-Addressing 标头,但我猜根据您的 WSDL,服务器可能不会接受没有 WS-Addressing 的消息。

于 2013-04-22T17:17:41.913 回答
0

刚刚发现缺少标题。wsa:MessageID如果通过 SOAP 请求传递,则不会出现错误。在我看来,这是一种奇怪的行为,因为它wsa:MessageID在 WS-A 1.0 规范中被描述为可选标头。

于 2013-04-23T10:25:30.853 回答