I corrected the code below as it was missing a name space in the setoperation
name and
I had a slight mistake in registering the type mapping. However the soap
messages sent and
received by the WSDL2Java generated code and mine are exactly the same, but
when my code received the
reply it gets the sax exception. I set break point in the Axis code and it
throws the exception
when examining the reply value of "450" not sure why. One of you experts out
there should be able to
look at the code and tell me what I am missing. I did search the archives as
well with no luck.
Ross
-----------
I am using Java2Wsdl and WSDL2Java to create a web service and also invoke it.
This all works fine.
However, in my end use of axis, in an applicaiton developlent tool, I cannot
use the generated
XXXSoapBIndingStub.java code, rather I need to dynamically create the call. In
looking at the
code that WSDL2Java generates I have tried to distill that down. However in my
code when I call the
service, I get the error SAXException: Found character data inside an array
element while deserializing,
even though the same SOAP messages are send in both cases. This leads me to
believe that I am
not setting up something correctly when invoking the web service. However I am
at a loss to
determine what I am missing. The service is a "wrapped" service. I only have
this problem for
an array of simple types. Using an array of benas things work (though the code
below would
be a tad different.
Any thoughts?
Ross
------------ Source Code Simplified version ----------------------------
public class CallService {
public static void main(String[] args) {
try {
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress("http://localhost:6060/axis/services/SimpleWrap");
call.setOperationName(new QName("urn:x.SimpleWrap","srIntArray"));
call.setOperationStyle(org.apache.axis.constants.Style.WRAPPED);
call.setOperationUse(org.apache.axis.constants.Use.LITERAL);
call.setUseSOAPAction(true);
call.setSOAPActionURI("");
call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR,
Boolean.FALSE);
call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS,
Boolean.FALSE);
call.setEncodingStyle(null);
call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
service.setTypeMappingVersion("1.2");
Object o = Array.newInstance(int.class, 0);
Class cls = o.getClass();
call.registerTypeMapping(cls, new
QName("http://www.w3.org/2001/XMLSchema", "int"), ArraySerializerFactory.class,
ArrayDeserializerFactory.class);
call.addParameter(new QName("urn:x.SimpleWrap", "values"), new
QName("http://www.w3.org/2001/XMLSchema", "int"),
ParameterMode.IN);
call.setReturnType(new
javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "int"));
call.setReturnClass(int[].class);
call.setReturnQName(new
javax.xml.namespace.QName("urn:x.SimpleWrap", "srIntArrayReturn"));
/* gather up the input parameters */
Object[] parms = new Object[1];
int[] x = new int[2];
x[0] = 450;
x[1] = 340;
parms[0] = x;
/* make the call */
Object ret = call.invoke(parms);
} catch (Exception e) {
System.out.println("Error on Web Serivce call:" + e);
e.printStackTrace();
}
}
}
--------- Message out ----------------
POST /axis/services/SimpleWrap HTTP/1.0 Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.2 Host: localhost:6060 Cache-Control: no-cache Pragma:
no-cache SOAPAction: "" Content-Length: 351 <?xml version="1.0"
encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<srIntArray xmlns="urn:x.SimpleWrap">
<values>450</values>
<values>340</values>
</srIntArray>
</soapenv:Body>
</soapenv:Envelope>
------- Message back --------------------------
HTTP/1.1 200 OK Set-Cookie: JSESSIONID=A60F8B42F502CD990879CF54B1049F12;
Path=/axis Content-Type: text/xml;charset=utf-8 Date: Thu, 28 Jul 2005 19:46:04
GMT Server: Apache-Coyote/1.1 Connection: close <?xml version="1.0"
encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<srIntArrayResponse xmlns="urn:x.SimpleWrap">
<srIntArrayReturn>450</srIntArrayReturn>
<srIntArrayReturn>340</srIntArrayReturn>
</srIntArrayResponse>
</soapenv:Body>
</soapenv:Envelope>
---------- WSDL ------------------
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="urn:x.SimpleWrap"
xmlns:impl="urn:x.SimpleWrap" xmlns:intf="urn:x.SimpleWrap"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<!--WSDL created by Apache Axis version: 1.2
Built on May 03, 2005 (02:20:24 EDT)-->
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:x.SimpleWrap" elementFormDefault="qualified">
<element name="add">
<complexType>
<sequence>
<element name="a" type="xsd:int"/>
<element name="b" type="xsd:int"/>
</sequence>
</complexType>
</element>
<element name="addResponse">
<complexType>
<sequence>
<element name="addReturn" type="xsd:int"/>
</sequence>
</complexType>
</element>
<element name="srInfo">
<complexType>
<sequence>
<element name="info" type="impl:Info"/>
</sequence>
</complexType>
</element>
<complexType name="Info">
<sequence>
<element name="age" type="xsd:int"/>
<element name="name" nillable="true" type="xsd:string"/>
<element name="phone" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<element name="srInfoResponse">
<complexType>
<sequence>
<element name="srInfoReturn" type="impl:Info"/>
</sequence>
</complexType>
</element>
<element name="srInfoArray">
<complexType>
<sequence>
<element name="info" type="impl:Info" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
<element name="srInfoArrayResponse">
<complexType>
<sequence>
<element name="srInfoArrayReturn" type="impl:Info" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
<element name="srIntArray">
<complexType>
<sequence>
<element name="values" type="xsd:int" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
<element name="srIntArrayResponse">
<complexType>
<sequence>
<element name="srIntArrayReturn" type="xsd:int" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="srInfoArrayResponse">
<wsdl:part name="parameters" element="impl:srInfoArrayResponse"/>
</wsdl:message>
<wsdl:message name="srInfoArrayRequest">
<wsdl:part name="parameters" element="impl:srInfoArray"/>
</wsdl:message>
<wsdl:message name="srInfoResponse">
<wsdl:part name="parameters" element="impl:srInfoResponse"/>
</wsdl:message>
<wsdl:message name="srIntArrayResponse">
<wsdl:part name="parameters" element="impl:srIntArrayResponse"/>
</wsdl:message>
<wsdl:message name="addRequest">
<wsdl:part name="parameters" element="impl:add"/>
</wsdl:message>
<wsdl:message name="srInfoRequest">
<wsdl:part name="parameters" element="impl:srInfo"/>
</wsdl:message>
<wsdl:message name="addResponse">
<wsdl:part name="parameters" element="impl:addResponse"/>
</wsdl:message>
<wsdl:message name="srIntArrayRequest">
<wsdl:part name="parameters" element="impl:srIntArray"/>
</wsdl:message>
<wsdl:portType name="SimpleWrap">
<wsdl:operation name="add">
<wsdl:input name="addRequest" message="impl:addRequest"/>
<wsdl:output name="addResponse" message="impl:addResponse"/>
</wsdl:operation>
<wsdl:operation name="srInfo">
<wsdl:input name="srInfoRequest" message="impl:srInfoRequest"/>
<wsdl:output name="srInfoResponse" message="impl:srInfoResponse"/>
</wsdl:operation>
<wsdl:operation name="srInfoArray">
<wsdl:input name="srInfoArrayRequest"
message="impl:srInfoArrayRequest"/>
<wsdl:output name="srInfoArrayResponse"
message="impl:srInfoArrayResponse"/>
</wsdl:operation>
<wsdl:operation name="srIntArray">
<wsdl:input name="srIntArrayRequest" message="impl:srIntArrayRequest"/>
<wsdl:output name="srIntArrayResponse"
message="impl:srIntArrayResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="SimpleWrapSoapBinding" type="impl:SimpleWrap">
<wsdlsoap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="add">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="addRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="addResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="srInfo">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="srInfoRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="srInfoResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="srInfoArray">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="srInfoArrayRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="srInfoArrayResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="srIntArray">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="srIntArrayRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="srIntArrayResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SimpleWrapService">
<wsdl:port name="SimpleWrap" binding="impl:SimpleWrapSoapBinding">
<wsdlsoap:address location="http://localhost:8080/SimpleWrap"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>