I am trying to run a apache axis2 webservice client and Im getting thrown an exeption like given below
org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement {http://schemas.xmlsoap.org/soap/envelope/}Body at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
Here is the wsdl for the webservice
<?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>
Following are the soap request and response packets from soap ui
SOAP REQUEST
<?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 RESPONSE
<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>
But by the time the response is reaching the client stub, stub receives it as follows
<?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>
Here the Soap and Body are encapsulated twice
As a result of this, client stub is unable to parse and throwing the following error.
org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement {http://schemas.xmlsoap.org/soap/envelope/}Body at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
Client Code
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();
}
}
}