Skip to content Skip to sidebar Skip to footer

Android Wsdl Web Service Ksoap2

I am trying to connect to a web service via an Android device by using the ksoap2 library. I've gotten it to work on two different services fine, but now I've ran into a problem.

Solution 1:

I had similar problems in the past. I'll give you an example of a part i had to fix in my application and how i did, check if you did these steps in your case: In the wsdl there was:

<messagename="invokeService"><partname="serviceName"type="xsd:string"/><partname="documents"type="tns:uriList"/><partname="literalDocs"type="ns1:stringArray"/><partname="connID"type="xsd:long"/><partname="gateParams"type="tns:gateRuntimeParameterArray"/><partname="userCtx"type="tns:userContext"/></message>

So I had to follow these steps: 1- check if your classes implementing KvmSerializable are accurately defined and not missing anything (this is cruciale for complex types)

2-Add ALL the necessary soap object properties that you need, for example in my case :

//for the part: <part name="serviceName"type="xsd:string"/>
SoapObject.addProperty("serviceName", whateverServiceNameItWas);

//for the part: <part name="documents"type="tns:uriList"/>,where uriList was a complex type
PropertyInfo pi = new PropertyInfo();
pi.setName("documents");
pi.setValue(usrOptPr.getDocuments());
pi.setType(UriList.class);
sobj.addProperty(pi);

etc... 3-Build the enveloppe:

SoapSerializationEnvelopesoapEnvelope=newSoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.setOutputSoapObject(SoapObject);

4- Add mappings between complex types(ie local class that implement kvmserializable, and the real matching classes on the web service)

//---------------------------------------------------------------------------------------// MAPPINGS:// A mapping tells the ksoap what class to generate.// Complex data types that are not mapped are generated as SoapObjects.// The mapping is required for both the request and the response.//---------------------------------------------------------------------------------------//for example the UriList above     
soapEnvelope.addMapping(theNamespace, UriList.class.getSimpleName(), UriList.class);

5- Add marshalling:(Marshalling uses java serialization to change Objects to stream of data to be unmarshalled on the web service.)

MarshalfloatMarshal=newMarshalFloat();
floatMarshal.register(soapEnvelope);

6- Use AndroidHttpTransport to call the web service UPDATE I also noticed that you have in the browser request:

<d4p1:Schools i:nil="true" />

While in Android:

<Schoolsi:type="d:string"></Schools>

Sometimes ksoap2 bugs with such a scenario, i had the same case so what i did is i just removed (commented out, since it allows nil ie null values) this param (ie schools) from its specific class that implements kvmserializable ( of course you will have to modify other stuff in the class like "getPropertyCount" and "getPropertyInfo" to adapt to this change). When i did that it worked, so try that and let me know.

Post a Comment for "Android Wsdl Web Service Ksoap2"