我有一个用 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 标头?