Hi
I am facing a problem in sending an array of complex object from a J2ME Client using KSOAP to .net web service (Soap services).
my TestSoap.java file has a setArr() method which takes an array of PropHeaderMapBin object and sends it to the web service which returns an integer (count of PropHeaderMapBin objects)
TestSoap.java
package org.tempuri;
import com.n9ciphers.test.Constants;
import java.util.Vector;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;
import org.tempuri.PropHeaderMapBin;
public final class TestSoap {
public int setArr(PropHeaderMapBin[] inArr) throws Exception {
SoapObject _client = new SoapObject("http://tempuri.org/", "SetArr");
SoapObject[] _propHeaderMapBinSO = new SoapObject[inArr.length];
PropHeaderMapBin[] prop = inArr;
//PropHeaderMapBin[] prop = new PropHeaderMapBin[inArr.length];
Vector _propVector = new Vector(inArr.length);
if (inArr != null) {
//System.out.println("_len " + inArr.length );
for (int i = 0; i < inArr.length; i++) {
_propHeaderMapBinSO[i] = new SoapObject("http://tempuri.org/", "PropHeaderMapBin");
_propHeaderMapBinSO[i].addProperty("PropertyName", prop[i].getPropertyName());
_propHeaderMapBinSO[i].addProperty("value", prop[i].getValue());
_propHeaderMapBinSO[i].addProperty("HeaderText", prop[i].getHeaderText());
_propHeaderMapBinSO[i].addProperty("label", prop[i].getLabel());
_propVector.addElement(_propHeaderMapBinSO[i]);
}
}
_client.addProperty(pi, _propVector);
SoapSerializationEnvelope _envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
_envelope.addMapping("http://www.tempuri.org/", "PropHeaderMapBin", new PropHeaderMapBin().getClass());
//_envelope.addTemplate (_client);
_envelope.bodyOut = _client;
_envelope.dotNet = true;
HttpTransport _ht = new HttpTransport(Constants.endPoint + "Test.asmx");
_ht.debug = true;
_ht.call("http://tempuri.org/SetArr", _envelope);
//System.out.println("response: " + result.toString());
System.out.println("Request Dump:" + _ht.requestDump);
//Dialog.show("Request Dump", _ht.requestDump, Dialog.TYPE_INFO, null, "OK", null);
System.out.println("Response Dump:" + _ht.responseDump);
//Dialog.show("Response Dump", _ht.responseDump, Dialog.TYPE_INFO, null, "OK", null);
return Integer.parseInt(_envelope.getResponse().toString());
//return 0;
}
}
Output of setArr() method call. the server does not recognize the datatype of the objects in array and it sets the arraytype to anytype[3] and returns a 0 instead of 3.
Request Dump:
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
<SetArr xmlns="http://tempuri.org/" id="o0" c:root="1">
<inArr i:type="c:Array" c:arrayType="d:anyType[3]">
<item i:type="n0:PropHeaderMapBin" xmlns:n0="http://tempuri.org/">
<PropertyName i:type="d:string">1</PropertyName>
<value i:type="d:string">1</value>
<HeaderText i:type="d:string">Pradhan</HeaderText>
<label i:type="d:string">Pradhan</label>
</item>
<item i:type="n1:PropHeaderMapBin" xmlns:n1="http://tempuri.org/">
<PropertyName i:type="d:string">2</PropertyName>
<value i:type="d:string">2</value>
<HeaderText i:type="d:string">Kavya</HeaderText>
<label i:type="d:string">Kavya</label>
</item>
<item i:type="n2:PropHeaderMapBin" xmlns:n2="http://tempuri.org/">
<PropertyName i:type="d:string">3</PropertyName>
<value i:type="d:string">3</value>
<HeaderText i:type="d:string">Puchi</HeaderText>
<label i:type="d:string">Puchi</label>
</item>
</inArr>
</SetArr>
</v:Body>
</v:Envelope>
Response Dump:<?xml version="1.0" encoding="utf-8"?>
<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>
<SetArrResponse xmlns="http://tempuri.org/">
<SetArrResult>0</SetArrResult>
</SetArrResponse>
</soap:Body>
</soap:Envelope>
response = 0
my wsdl file for reference
<wsdl:definitions targetNamespace="http://tempuri.org/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="GetArr">
<s:complexType/>
</s:element>
<s:element name="GetArrResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetArrResult" type="tns:ArrayOfPropHeaderMapBin"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="ArrayOfPropHeaderMapBin">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="PropHeaderMapBin" nillable="true" type="tns:PropHeaderMapBin"/>
</s:sequence>
</s:complexType>
<s:complexType name="PropHeaderMapBin">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="PropertyName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="value" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="HeaderText" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="label" type="s:string"/>
</s:sequence>
</s:complexType>
<s:element name="SetArr">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="inArr" type="tns:ArrayOfPropHeaderMapBin"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="SetArrResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="SetArrResult" type="s:int"/>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="GetArrSoapIn">
<wsdl:part name="parameters" element="tns:GetArr"/>
</wsdl:message>
<wsdl:message name="GetArrSoapOut">
<wsdl:part name="parameters" element="tns:GetArrResponse"/>
</wsdl:message>
<wsdl:message name="SetArrSoapIn">
<wsdl:part name="parameters" element="tns:SetArr"/>
</wsdl:message>
<wsdl:message name="SetArrSoapOut">
<wsdl:part name="parameters" element="tns:SetArrResponse"/>
</wsdl:message>
<wsdl:portType name="TestSoap">
<wsdl:operation name="GetArr">
<wsdl:input message="tns:GetArrSoapIn"/>
<wsdl:output message="tns:GetArrSoapOut"/>
</wsdl:operation>
<wsdl:operation name="SetArr">
<wsdl:input message="tns:SetArrSoapIn"/>
<wsdl:output message="tns:SetArrSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TestSoap" type="tns:TestSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="HelloWorld">
<soap:operation soapAction="http://tempuri.org/HelloWorld" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetArr">
<soap:operation soapAction="http://tempuri.org/GetArr" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="SetArr">
<soap:operation soapAction="http://tempuri.org/SetArr" 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="TestSoap12" type="tns:TestSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetArr">
<soap12:operation soapAction="http://tempuri.org/GetArr" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="SetArr">
<soap12:operation soapAction="http://tempuri.org/SetArr" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Test">
<wsdl:port name="TestSoap" binding="tns:TestSoap">
<soap:address location="http://xxx.xxx.xxx.xxx/Services/Test.asmx"/>
</wsdl:port>
<wsdl:port name="TestSoap12" binding="tns:TestSoap12">
<soap12:address location="http://xxx.xxx.xxx.xxx/Services/Test.asmx"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I wud appreciate any help if some one has already faced this kind of issue and resolved it successfully.