在axis2的响应中封装了两次Soap和Body标签

Posted

技术标签:

【中文标题】在axis2的响应中封装了两次Soap和Body标签【英文标题】:Soap and Body tags encapsulated twice in the response in axis2 【发布时间】:2013-04-17 09:05:12 【问题描述】:

我正在尝试运行一个 apache axis2 webservice 客户端,但我得到了一个如下所示的异常

org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement http://schemas.xmlsoap.org/soap/envelope/Body 在 org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)

这是 web 服务的 wsdl

<?xml version="1.0" encoding="UTF-8"?> 
- 
<wsdl:definitions targetNamespace="http://wtp" 
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" 
xmlns:ns="http://wtp" xmlns:ns1="http://org.apache.axis2/xsd" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> 
<wsdl:documentation> Please Type your service description here 
</wsdl:documentation> 
- 
<wsdl:types> 
- 
<xs:schema targetNamespace="http://wtp" elementFormDefault="qualified" 
attributeFormDefault="qualified"> 
- 
<xs:element name="authenticate"> 
- 
<xs:complexType> 
- 
<xs:sequence> 
<xs:element name="loginname" type="xs:string" nillable="true" 
minOccurs="0" /> 
<xs:element name="password" type="xs:string" nillable="true" 
minOccurs="0" /> 
</xs:sequence> 
</xs:complexType> 
</xs:element> 
- 
<xs:element name="authenticateResponse"> 
- 
<xs:complexType> 
- 
<xs:sequence> 
<xs:element name="return" type="xs:int" minOccurs="0" /> 
</xs:sequence> 
</xs:complexType> 
</xs:element> 
</xs:schema> 
</wsdl:types> 
- 
<wsdl:message name="authenticateRequest"> 
<wsdl:part name="parameters" element="ns:authenticate" /> 
</wsdl:message> 
- 
<wsdl:message name="authenticateResponse"> 
<wsdl:part name="parameters" element="ns:authenticateResponse" /> 
</wsdl:message> 
- 
<wsdl:portType name="LoginPortType"> 
- 
<wsdlperation name="authenticate"> 
<wsdl:input wsaw:Action="urn:authenticate" message="ns:authenticateRequest" /> 
<wsdlutput wsaw:Action="urn:authenticateResponse" 
message="ns:authenticateResponse" /> 
</wsdlperation> 
</wsdl:portType> 
- 
<wsdl:binding name="LoginSoap11Binding" type="ns:LoginPortType"> 
<soap:binding style="document" 
transport="http://schemas.xmlsoap.org/soap/http" /> 
- 
<wsdlperation name="authenticate"> 
<soapperation style="document" soapAction="urn:authenticate" /> 
- 
<wsdl:input> 
<soap:body use="literal" /> 
</wsdl:input> 
- 
<wsdlutput> 
<soap:body use="literal" /> 
</wsdlutput> 
</wsdlperation> 
</wsdl:binding> 
- 
<wsdl:binding name="LoginSoap12Binding" type="ns:LoginPortType"> 
<soap12:binding style="document" 
transport="http://schemas.xmlsoap.org/soap/http" /> 
- 
<wsdlperation name="authenticate"> 
<soap12peration style="document" soapAction="urn:authenticate" /> 
- 
<wsdl:input> 
<soap12:body use="literal" /> 
</wsdl:input> 
- 
<wsdlutput> 
<soap12:body use="literal" /> 
</wsdlutput> 
</wsdlperation> 
</wsdl:binding> 
- 
<wsdl:binding name="LoginHttpBinding" type="ns:LoginPortType"> 
<http:binding verb="POST" /> 
- 
<wsdlperation name="authenticate"> 
<httpperation location="authenticate" /> 
- 
<wsdl:input> 
<mime:content type="text/xml" part="parameters" /> 
</wsdl:input> 
- 
<wsdlutput> 
<mime:content type="text/xml" part="parameters" /> 
</wsdlutput> 
</wsdlperation> 
</wsdl:binding> 
- 
<wsdl:service name="Login"> 
- 
<wsdl:port name="LoginHttpSoap11Endpoint" binding="ns:LoginSoap11Binding"> 
<soap:address 
location="http://localhost:8080/Navigato/services/Login.LoginHttpSoap11Endpoint/" /> 
</wsdl:port> 
- 
<wsdl:port name="LoginHttpSoap12Endpoint" binding="ns:LoginSoap12Binding"> 
<soap12:address 
location="http://localhost:8080/Navigato/services/Login.LoginHttpSoap12Endpoint/" /> 
</wsdl:port> 
- 
<wsdl:port name="LoginHttpEndpoint" binding="ns:LoginHttpBinding"> 
<http:address 
location="http://localhost:8080/Navigato/services/Login.LoginHttpEndpoint/" /> 
</wsdl:port> 
</wsdl:service> 
</wsdl:definitions> 

以下是来自soap ui的soap请求和响应包

SOAP 请求

<?xml version='1.0' encoding='utf-8'?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
<soapenv:Body> 
<ns1:authenticate xmlns:ns1="http://wtp"> 
<ns1:loginname>john</ns1:loginname> 
<ns1:password>123</ns1:password> 
</ns1:authenticate> 
</soapenv:Body> 
</soapenv:Envelope>

SOAP 响应

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
<soapenv:Body> 
<ns:authenticateResponse xmlns:ns="http://wtp"> 
<ns:return>1</ns:return> 
</ns:authenticateResponse> 
</soapenv:Body> 
</soapenv:Envelope> 

但是当响应到达客户端存根时,存根收到它 如下

<?xml version='1.0' encoding='utf-8'?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
<soapenv:Body> 
<soapenv:Envelope> 
<soapenv:Body> 
<ns:authenticateResponse xmlns:ns="http://wtp"> 
<ns:return>1</ns:return> 
</ns:authenticateResponse> 
</soapenv:Body> 
</soapenv:Envelope> 
</soapenv:Body> 
</soapenv:Envelope> 

这里Soap和Body被封装了两次

因此,客户端存根无法解析并抛出 以下错误。

org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement http://schemas.xmlsoap.org/soap/envelope/Body 在 org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)

客户代码

public class LoginClient 

    public static void main(String args[])
    
        try 
            LoginStub stub = new LoginStub();
            Authenticate auth = new Authenticate();
            auth.setLoginname("john");
            auth.setPassword("123");
            AuthenticateResponse res = stub.authenticate(auth);
            System.out.println(res.get_return());
         catch (AxisFault e) 
            // TODO Auto-generated catch block
            e.printStackTrace();
         catch (RemoteException e) 
            // TODO Auto-generated catch block
            e.printStackTrace();
        

    

【问题讨论】:

【参考方案1】:

您的客户端代码是如何编写的?..您是否正确设置了消息的内容类型.. 在某些时候,axis2 认为该消息不是肥皂消息,并用肥皂信封再次包装.. 当您在axis2中收到响应时,检查它的内容类型..它应该是text/xml

【讨论】:

内容类型的响应以 text/xml 本身的形式给出。我已经提供了客户端,这是一个添加到上述问题的测试场景。提前致谢。

以上是关于在axis2的响应中封装了两次Soap和Body标签的主要内容,如果未能解决你的问题,请参考以下文章

Axis2 Web 服务名称空间前缀转换

关于使用Axis2 webservice 处理Fault响应时抛org.apache.axis2.AxisFault的分析

当内容类型为“text/xml”时,Axis2 发送多部分响应

axis2设置soap1.1或soap1.2协议

Eclipse + Apache Axis2 发布SOAP WebService第一个程序Hello Axis2 SOAP!

Axis2的下载和安装