我正在尝试运行一个apache axis2 webservice客户端,我会抛出一个如下所示的例外
org.apache.axis2.AxisFault:org.apache.axis2.databinding.ADBException:意外的子元素{http://schemas.xmlsoap.org/soap/envelope/}正文 在org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
这是webservice的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的肥皂请求和响应数据包
<?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>
<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>
这里肥皂和身体被封装两次
因此,客户端存根无法解析并抛出 跟随错误。
org.apache.axis2.AxisFault:org.apache.axis2.databinding.ADBException:意外的子元素{http://schemas.xmlsoap.org/soap/envelope/}正文 在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();
}
}
}
答案 0 :(得分:0)
您的客户端代码是如何编写的?..您是否正确设置了消息的内容类型.. 在某些时候,axis2认为该消息不是肥皂消息,并再次用肥皂信封包裹.. 当你在axis2收到响应时,检查它的内容类型..它应该是text / xml