Soap and Body tags encapsulated twice in the response in axis2 - axis2

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();
}
}
}

How is your client code is written?..Have you set the content-type of the messagecorrectly..
At some point, axis2 thinks the message is not a soap message and wraps again with a soap envelope..
When you receive the response in axis2 check the content-type of it..it should be text/xml

Related

How do i add soapHeader to service built in asp.net core

I built a service in asp.net core which is accessible via wsdl below. I want to add authheader to this wsdl. How do i achieve this? I am able to test this service using Postman with success. I used below code to make it look like a soap service.
app.UseSoapEndpoint<SampleService>("/webservice/SS.asmx", new BasicHttpBinding(), SoapSerializer.XmlSerializer);
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://tempuri.org/" name="SampleService">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<xs:import namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
<xs:import namespace="http://schemas.datacontract.org/2004/07/System"/>
<xs:element name="Test">
<xs:complexType>
<xs:sequence/>
</xs:complexType>
</xs:element>
<xs:element name="TestResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="TestResult" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="SampleService_Test_InputMessage">
<wsdl:part name="parameters" element="tns:Test"/>
</wsdl:message>
<wsdl:message name="SampleService_Test_OutputMessage">
<wsdl:part name="parameters" element="tns:TestResponse"/>
</wsdl:message>
<wsdl:portType name="SampleService">
<wsdl:operation name="Test">
<wsdl:input message="tns:SampleService_Test_InputMessage"/>
<wsdl:output message="tns:SampleService_Test_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_SampleService" type="tns:SampleService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Test">
<soap:operation soapAction="http://tempuri.org/SampleService/Test" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SampleService">
<wsdl:port name="BasicHttpBinding_SampleService" binding="tns:BasicHttpBinding_SampleService">
<soap:address location="http://localhost:32156/webservice/SS.asmx"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

Dpws web service with event - Wcf client example or suggestions sought

My device has a DPWS web service with a single output (wsdl:output) that I need to subscribe to with a Wcf client
The client is a regular .Net 4.0 application - not .net-micro-framework.
I need an example or tutorial or other resource relating to building such a client to such a service.
'Add Service Reference' produces non-working code, 'Add Web Reference' hangs.
The Wsdl is below.
If there's any further information required to answer this question please let me know.
Many thanks
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:p="http://schemas.xmlsoap.org/ws/2006/02/devprof"
xmlns:po="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:tns="http://www.test.fi/wsdl/THLGateway"
xmlns:wse="http://schemas.xmlsoap.org/ws/2004/08/eventing"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap12/"
name="THLGateway"
targetNamespace="http://www.test.fi/wsdl/THLGateway">
<po:Policy Id="EventingServicePolicy">
<p:profile />
<p:PushDelivery />
<p:DurationExpiration />
<p:ActionFilter />
</po:Policy>
<types>
<xsd:schema targetNamespace="http://www.test.fi/wsdl/THLGateway"
elementFormDefault="qualified">
<xsd:element name="thlChangeEvent">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="gatewayID"
type="xsd:string"
nillable ="true"
minOccurs="0"/>
<xsd:element name="nodeID"
type="xsd:string"
minOccurs="0"
nillable ="true"/>
<xsd:element name="temperature"
nillable ="true"
minOccurs="0"
type="xsd:double"/>
<xsd:element name="humidity"
nillable ="true"
minOccurs="0"
type="xsd:double"/>
<xsd:element name="light"
nillable ="true"
minOccurs="0"
type="xsd:double"/>
<xsd:element name="battery"
nillable ="true"
minOccurs="0"
type="xsd:double"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</types>
<wsdl:message name="thlChangeResponse">
<wsdl:part name="parameters"
element="tns:thlChangeEvent"/>
</wsdl:message>
<wsdl:portType name="THLGatewayPortType"
wse:EventSource="true">
<wsdl:operation name="thlChange">
<wsdl:output message="tns:thlChangeResponse"/>
</wsdl:operation>
</wsdl:portType>
<binding name="THLGatewayPortType"
type="tns:THLGatewayPortType">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<po:PolicyReference URI="#EventingServicePolicy"
wsdl:required="true" />
<wsdl:operation name="thlChange">
<soap:operation style="document"/>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</binding>
<service name="THLGateway">
<port name="THLGatewayPortType"
binding="tns:THLGatewayPortType">
<soap:address location="http://192.168.0.93:80/dpws/ws01"/>
</port>
</service>
</definitions>
Single Output means that this service generates Events. You will want to look for WS-Eventing. It is not supported in stock .Net 4.0 WCF, but a project on CodeProject is implementing this functionality on top of WCF. Are you still interested in this topic?

Service parameter always null, but I can see it in the trace

I'm having trouble implementing a service based off of a third-party wsdl. The third-party calls into my service and I can see the data in the trace, but my service parameters keep ending up null after deserialization.
As you can see from the trace, the alertXML node contains a XML document as a string. In the service code, this alertXML string is always null. Is there some special processing I need to do to handle this XML-as-a-string scenario?
Barring that, is there any way for me to just get a hold of the whole envelope so that I can parse the thing out?
Thanks
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<EventID>0</EventID>
<Type>3</Type>
<SubType Name="Information">0</SubType>
<Level>8</Level>
<TimeCreated SystemTime="2011-07-08T17:46:14.7804786Z" />
<Source Name="System.ServiceModel.MessageLogging" />
<Correlation ActivityID="{54a3d088-5393-45a7-ae97-0bcd636f1750}" />
<Execution ProcessName="w3wp" ProcessID="3468" ThreadID="17" />
<Channel/>
<Computer>COMPUTER</Computer>
</System>
<ApplicationData>
<TraceData>
<DataItem>
<MessageLogTraceRecord Time="2011-07-08T13:46:14.7804786-04:00" Source="TransportReceive" Type="System.ServiceModel.Channels.BufferedMessage" xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
<HttpRequest>
<Method>POST</Method>
<QueryString></QueryString>
<WebHeaders>
<Content-Length>1807</Content-Length>
<Content-Type>text/xml; charset=utf-8</Content-Type>
<Expect>100-continue</Expect>
<Host>host</Host>
<User-Agent>Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.3623)</User-Agent>
<SOAPAction>"http://www.xyz.com/wsdl/ProcessXML"</SOAPAction>
</WebHeaders>
</HttpRequest>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ProcessXML xmlns="http://www.xyz.com/wsdl/">
<alertXml><?xml version="1.0" encoding="UTF-8"?><XMLOutgoing>MORE XML STRING</XMLOutgoing></alertXml>
</ProcessXML>
</soap:Body>
</soap:Envelope>
</MessageLogTraceRecord>
</DataItem>
</TraceData>
</ApplicationData>
EDIT:
The wsdl is:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="http://www.xyz.com/wsdl/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
targetNamespace="http://www.xyz.com/wsdl/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://www.xyz.com/wsdl/">
<s:element name="ProcessXML">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="alertXml" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="ProcessXMLResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="ProcessXMLResult">
<s:complexType mixed="true">
<s:sequence>
<s:any/>
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="ProcessXMLSoapIn">
<wsdl:part name="parameters" element="tns:ProcessXML"/>
</wsdl:message>
<wsdl:message name="ProcessXMLSoapOut">
<wsdl:part name="parameters" element="tns:ProcessXMLResponse"/>
</wsdl:message>
<wsdl:message name="ProcessXMLHttpGetIn">
<wsdl:part name="alertXml" type="s:string"/>
</wsdl:message>
<wsdl:message name="ProcessXMLHttpGetOut">
<wsdl:part name="Body"/>
</wsdl:message>
<wsdl:message name="ProcessXMLHttpPostIn">
<wsdl:part name="alertXml" type="s:string"/>
</wsdl:message>
<wsdl:message name="ProcessXMLHttpPostOut">
<wsdl:part name="Body"/>
</wsdl:message>
<wsdl:portType name="GenericServiceSoap">
<wsdl:operation name="ProcessXML">
<wsdl:input message="tns:ProcessXMLSoapIn"/>
<wsdl:output message="tns:ProcessXMLSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="GenericServiceHttpGet">
<wsdl:operation name="ProcessXML">
<wsdl:input message="tns:ProcessXMLHttpGetIn"/>
<wsdl:output message="tns:ProcessXMLHttpGetOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="GenericServiceHttpPost">
<wsdl:operation name="ProcessXML">
<wsdl:input message="tns:ProcessXMLHttpPostIn"/>
<wsdl:output message="tns:ProcessXMLHttpPostOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="GenericServiceSoap" type="tns:GenericServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ProcessXML">
<soap:operation soapAction="http://www.xyz.com/wsdl/ProcessXML" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="GenericServiceSoap12" type="tns:GenericServiceSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ProcessXML">
<soap12:operation soapAction="http://www.xyz.com/wsdl/ProcessXML" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="GenericServiceHttpGet" type="tns:GenericServiceHttpGet">
<http:binding verb="GET"/>
<wsdl:operation name="ProcessXML">
<http:operation location="/ProcessXML"/>
<wsdl:input>
<http:urlEncoded/>
</wsdl:input>
<wsdl:output>
<mime:content part="Body" type="text/xml"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="GenericServiceHttpPost" type="tns:GenericServiceHttpPost">
<http:binding verb="POST"/>
<wsdl:operation name="ProcessXML">
<http:operation location="/ProcessXML"/>
<wsdl:input>
<mime:content type="application/x-www-form-urlencoded"/>
</wsdl:input>
<wsdl:output>
<mime:content part="Body" type="text/xml"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="GenericService">
</wsdl:service>
</wsdl:definitions>
The skeleton of the service code is:
Public Function ProcessXML(request As ProcessXMLRequest) As ProcessXMLResponse Implements GenericServiceSoap.ProcessXML
'request.Body is a non-null object but request.Body.alertXml is null
End Function
To send XML as a parameter or a property in a DataContract in WCF you need to use XmlElement for the .NET type of the parameter or property. Based on the WSDL in the question, the alertXml will be serialized as a string not XML by WCF. Here is what the WSDL for an XML operation parameter would look like:
<xs:element name="alertXml" nillable="true" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:any minOccurs="0" processContents="lax"/>
</xs:sequence>
</xs:complexType>
</xs:element>
To see what all the WSDL should look like, implement a service like this:
[ServiceContract]
public interface IService1
{
[OperationContract]
string ProcessXml(XmlElement alertXml);
[OperationContract]
string ProcessSomeXml(ProcessXMLRequest xmlRequest);
}
[DataContract]
public class ProcessXMLRequest
{
public XmlElement someXml { get; set; }
}
//Service implementation
public class Service1 : IService1
{
public string ProcessXml(XmlElement alertXml)
{
XmlNode xmlToProcess = GetXmlToProcess(alertXml);
return string.Format("You entered: {0}", xmlToProcess.InnerText);
}
public string ProcessSomeXml(ProcessXMLRequest xmlRequest)
{
XmlNode xmlToProcess = GetXmlToProcess(xmlRequest.someXml);
return string.Format("You entered some: {0}", xmlToProcess.InnerText);
}
private XmlNode GetXmlToProcess(XmlElement alertXml)
{
var xmlToProcess = alertXml as XmlNode;
if (xmlToProcess == null)
{
var x = new XmlDocument();
x.LoadXml("<root>XML was null</root>");
xmlToProcess = x;
}
return xmlToProcess;
}
}

Problems importing WSDL using WCF

I'm trying with WCF to import WSDL for a web service provided by one of my company's partners. The web service is written in Java. I get this error:
Warning: Fault named FooException in operation getUnits cannot be imported. Unsupported WSDL, the fault message part must reference an element. This fault message does not reference an element. If you have edit access to the WSDL document, you can fix the problem by referencing a schema element using the 'element' attribute.
Well, not actually an error, but in the generated code FooException is ignored. FooException contains an error code which I really need.
I've shortened the WSDL and only kept one of the methods. I've also renamed some things (like the exception).
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="urn:testws.foo.se"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="urn:testws.foo.se"
xmlns:intf="urn:testws.foo.se"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema targetNamespace="urn:testws.foo.se" xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="ArrayOf_soapenc_string">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="soapenc:string[]"/>
</restriction>
</complexContent>
</complexType>
<complexType name="FooException">
<sequence>
<element name="errorCode" nillable="true" type="soapenc:string"/>
<element name="errorDescription" nillable="true" type="soapenc:string"/>
<element name="variables" nillable="true" type="impl:ArrayOf_soapenc_string"/>
</sequence>
</complexType>
<element name="FooException" type="impl:FooException" nillable="true" />
<complexType name="WsUnit">
<sequence>
<element name="id" nillable="true" type="soapenc:string"/>
<element name="name" nillable="true" type="soapenc:string"/>
</sequence>
</complexType>
<complexType name="ArrayOfWsUnit">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="impl:WsUnit[]"/>
</restriction>
</complexContent>
</complexType>
</schema>
</wsdl:types>
<wsdl:message name="getUnitsRequest">
</wsdl:message>
<wsdl:message name="getUnitsResponse">
<wsdl:part name="getUnitsReturn" type="impl:ArrayOfWsUnit"/>
</wsdl:message>
<wsdl:message name="FooException">
<wsdl:part name="fault" type="impl:FooException"/>
</wsdl:message>
<wsdl:portType name="MyTest">
<wsdl:operation name="getUnits">
<wsdl:input message="impl:getUnitsRequest" name="getUnitsRequest"/>
<wsdl:output message="impl:getUnitsResponse" name="getUnitsResponse"/>
<wsdl:fault message="impl:FooException" name="FooException"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MyTestSoapBinding" type="impl:MyTest">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getUnits">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getUnitsRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:testws.foo.se" use="encoded"/>
</wsdl:input>
<wsdl:output name="getUnitsResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:testws.foo.se" use="encoded"/>
</wsdl:output>
<wsdl:fault name="FooException">
<wsdlsoap:fault encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" name="FooException" namespace="urn:testws.foo.se" use="encoded"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="MyTestService">
<wsdl:port binding="impl:MyTestSoapBinding" name="MyTest">
<wsdlsoap:address location="http://localhost:8080/axis/services/MyTest"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I've tried to just change "type" to "element" in the message part for FooException, but it results in errors. What more do I need to do?

Axis2 client Unexpected subelement apple

I developed both a server and client application using Axis2 version 1.5.4, Java 1.6 and the server is deployed on tomcat 6.
The services are declared using annotations, so there is no .aar files or anything of that sort.
The WSDL was created automatically by Axis2.
The client was made using the stubs and parameters generated by WSDL2Java using the command:
%axis2_home%\bin\WSDL2Java -p com.audaxys.leaseclient.servicestub.generic -d adb -Eosv -s -g -u -uw -or -sp -S src/main/java -R src/main/resources --noBuildXML -uri %baseurl%/AppleFinderService.Rpc?wsdl
When the client app calls the method public Apple loadApple(String appType) the server responds returning one instance of Apple class, but the client is unable to de-serialize the response and throws this exception.
If you know how to fix this, could you please share it with me?
Any clues would be greatly appreciated, really!
Full stack trace:
org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement apple
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at com.audaxys.leaseclient.servicestub.generic.AppleFinderServiceStub.fromOM(AppleFinderServiceStub.java:1015)
at com.audaxys.leaseclient.servicestub.generic.AppleFinderServiceStub.loadApple(AppleFinderServiceStub.java:343)
at com.audaxys.lease.ws.client.TestDummyServices.testLoadApple(TestDummyServices.java:107)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.Exception: org.apache.axis2.databinding.ADBException: Unexpected subelement apple
at com.audaxys.www.namespaces.leasews.LoadAppleResponse$Factory.parse(LoadAppleResponse.java:454)
at com.audaxys.leaseclient.servicestub.generic.AppleFinderServiceStub.fromOM(AppleFinderServiceStub.java:981)
... 18 more
Caused by: org.apache.axis2.databinding.ADBException: Unexpected subelement apple
at com.audaxys.www.namespaces.leasews.LoadAppleResponse$Factory.parse(LoadAppleResponse.java:448)
... 19 more
ServiceDeclaration
package com.audaxys.lease.model.generic;
import .....;
#WebService(name="AppleFinderService", serviceName="AppleFinderService", portName="Rpc", targetNamespace="http://www.audaxys.com/namespaces/leasews")
#SOAPBinding(style = Style.RPC, parameterStyle = ParameterStyle.WRAPPED)
public class AppleFinderImpl {
#WebResult(name = "apple")
public Apple loadApple(String appType) {
Apple a = new Apple();
a.setAppleType(appType);
return a;
}
}
Apple class
package com.audaxys.lease.model.generic;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement(namespace="http://www.audaxys.com/namespaces/leasews")
public class Apple {
private String appleType;
public Apple() {
super();
}
public String getAppleType() {
return appleType;
}
public void setAppleType(String appleType) {
this.appleType = appleType;
}
}
WSDL
<?xml version="1.0" encoding="UTF-8" ?>
<definitions name="AppleFinderService" targetNamespace="http://www.audaxys.com/namespaces/leasews" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.audaxys.com/namespaces/leasews" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://jaxb.dev.java.net/array">
<types>
<xsd:schema>
<xsd:import namespace="http://www.audaxys.com/namespaces/leasews" schemaLocation="AppleFinderService.Rpc?xsd=AppleFinderService_schema1.xsd" />
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://jaxb.dev.java.net/array" schemaLocation="AppleFinderService.Rpc?xsd=AppleFinderService_schema2.xsd" />
</xsd:schema>
</types>
<message name="loadAppleResponse">
<part name="apple" type="tns:apple" />
</message>
<message name="getAppleArray">
<part name="arg0" type="xsd:string" />
</message>
<message name="loadApple">
<part name="arg0" type="xsd:string" />
</message>
<portType name="AppleFinderService">
<operation name="getAppleArray">
<input message="tns:getAppleArray" />
<output message="tns:getAppleArrayResponse" />
</operation>
<operation name="loadApple">
<input message="tns:loadApple" />
<output message="tns:loadAppleResponse" />
</operation>
</portType>
<binding name="RpcBinding" type="tns:AppleFinderService">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="getAppleArray">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" namespace="http://www.audaxys.com/namespaces/leasews" />
</input>
<output>
<soap:body use="literal" namespace="http://www.audaxys.com/namespaces/leasews" />
</output>
</operation>
<operation name="loadApple">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" namespace="http://www.audaxys.com/namespaces/leasews" />
</input>
<output>
<soap:body use="literal" namespace="http://www.audaxys.com/namespaces/leasews" />
</output>
</operation>
</binding>
<service name="AppleFinderService">
<port name="Rpc" binding="tns:RpcBinding">
<soap:address location="http://10.10.5.25:8080/lease.services/soap/services/AppleFinderService.Rpc/" />
</port>
</service>
</definitions>
XSD
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.audaxys.com/namespaces/leasews" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://www.audaxys.com/namespaces/leasews">
<xs:element name="apple" type="tns:apple" />
<xs:complexType name="apple">
<xs:sequence>
<xs:element minOccurs="0" name="appleType" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType final="#all" name="appleArray">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="item" nillable="true" type="tns:apple" />
</xs:sequence>
</xs:complexType>
</xs:schema>
Request
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<loadApple xmlns="http://www.audaxys.com/namespaces/leasews">
<arg0>Red</arg0>
</loadApple>
</soapenv:Body>
</soapenv:Envelope>
Responsse
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<rpcOp:loadAppleResponse xmlns:rpcOp="http://www.audaxys.com/namespaces/leasews">
<rpcOp:apple xmlns:ns3="http://com.audaxys.lease/" xmlns="">
<appleType>Red</appleType>
</rpcOp:apple>
</rpcOp:loadAppleResponse>
</soapenv:Body>
</soapenv:Envelope>
Your post is hard to read but I believe the problem is in the WSDL and XSD. You have an element, complexType and message part all with the same name "apple". I would try reworking the WSDL following the convention here:
<element name="Apple" type="tns:AppleType"/>
<complexType name="AppleType">
...
</complexType>
<message name="loadAppleResponse">
<part name="apple" element="tns:Apple"/>
</message>
I have faced the similiar kind of problem, I have annotated the EJB SLSB using JAX-WS API's and used RPC as the SOAP Bindind style.Deployed the EJB in JBoss5.1 and JBOSSWS generates the WSDL.
When I tested the Web Services by Axis1 client it worked fine, But while testing with Axis2 client, the request has sent to the server and even the DB transactions also was successfull.
But when the response came to the client, it says the Unexpected subelement return and so on. Then I changed the SOAP binding style it worked with Axis2.
#WebService
#SOAPBinding(style=Style.DOCUMENT, parameterStyle = ParameterStyle.WRAPPED)
public interface BillingAccountManagement_SEI { // TODO}