I have been struggling for hours trying to build the correct SOAP request using ksoap2 for Android with no luck. The ideal request looks like this:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthorizationToken xmlns="http://www.avectra.com/2005/">
<Token>string</Token>
</AuthorizationToken>
</soap:Header>
<soap:Body>
<ExecuteMethod xmlns="http://www.avectra.com/2005/">
<serviceName>string</serviceName>
<methodName>string</methodName>
<parameters>
<Parameter>
<Name>string</Name>
<Value>string</Value>
</Parameter>
</parameters>
</ExecuteMethod>
</soap:Body>
</soap:Envelope>
I am using the following code to generate my request:
SoapObject request = new SoapObject(NAMESPACE, METHOD);
request.addProperty("serviceName", SERVICENAME);
request.addProperty("methodName", METHODNAME);
SoapObject nestedParameters = new SoapObject(NAMESPACE, "parameters");
SoapObject param = new SoapObject(NAMESPACE, "Parameter");
param.addProperty("Name", name);
param.addProperty("Value", value);
nestedParameters.addSoapObject(param);
request.addSoapObject(nestedParameters);
SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.headerOut = new Element[1];
Element header = new Element().createElement(NAMESPACE, "AuthorizationToken");
Element token = new Element().createElement(NAMESPACE, "Token");
token.addChild(Node.TEXT, this.AUTH_TOKEN);
header.addChild(Node.ELEMENT, token);
envelope.headerOut[0] = header;
What ksoap2 is building is:
<v:Envelope xmlns:i="http://www.w3.org/1999/XMLSchema-instance" xmlns:d="http://www.w3.org/1999/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header>
<n0:AuthorizationToken xmlns:n0="http://www.avectra.com/2005/">
<n0:Token>string</n0:Token>
</n0:AuthorizationToken>
</v:Header>
<v:Body>
<ExecuteMethod xmlns="http://www.avectra.com/2005/" id="o0" c:root="1">
<serviceName>AHAWebServices</serviceName>
<methodName>MemberDirectory</methodName>
<parameters i:type="n1:parameters" xmlns:n1="http://www.avectra.com/2005/">
<Parameter i:type="n1:Parameter">
<Name>string</Name>
<Value>string</Value>
</Parameter>
</parameters>
</ExecuteMethod>
</v:Body>
</v:Envelope>
I have a feeling that the problem is in the header with the n0 prefixes but I have no clue how to get rid of them. I removed them from from the body by setting implicitTypes to true but I cannot find a similar setting for the header. I am new to SOAP so any other advice is greatly appreciated. Does anyone have an idea of how I could fix this?
When using KSOAP This worked for me
NOTE:
resolved the issue in my case. Banged my head but could not reason with why setting debug true helped resolve the issue.
Why do you need to use ksoap?
Simply have the static party of your SOAP request as a String, append the values to the static part and you can finally have the complete SOAP request. Finally use HTTP methods to send your post request.
No additional JARs
Also ksoap has issues like OOM for large responses, etc.
KSOAP OOM issue
You can use the following code