Right off the bat, here is my Soap call implementation, minus the irrelevant bits.
public class MySoapClient implements AbstractSoapClient
{
private String NAMESPACE = "http://www.examples.com/wsdl/MyService/";
private String METHOD_NAME = "getPersonDetails";
private String SOAP_ACTION = "http://www.examples.com/getPersonDetails/";
String URL = "http://192.168.0.10:8088/mockMyServiceBinding?WSDL";
public Object process() throws Exception
{
SoapSerializationEnvelope envelope = generateEnvelope();
return responseObject = makeCall(envelope);
}
private SoapSerializationEnvelope generateEnvelope()
{
// dont set a namespace for the requestobject, otherwise ksoap adds implicit namespaces onto request elements
SoapObject requestObject = new SoapObject("", METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes = true;
requestObject.addProperty("name", "Dave");
envelope.setOutputSoapObject(requestObject);
return envelope;
}
private Object makeCall(SoapSerializationEnvelope envelope)
{
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
return envelope.bodyIn;
}
catch (Exception e)
{
e.printStackTrace();
return e;
}
}
}
I think the problem is the SoapObject requestObject = new SoapObject("", METHOD_NAME);
part.
If I use SoapObject requestObject = new SoapObject("", METHOD_NAME);
Then I get this in the bodyOut :
<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>
<getPersonDetails xmlns="" id="o0" c:root="1">
<name>Dave</name>
</getPersonDetails>
</v:Body>
</v:Envelope>
If I use SoapObject requestObject = new SoapObject(NAMESPACE, METHOD_NAME);
Then I get this in the bodyOut :
<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>
<n0:getPersonDetails id="o0" c:root="1" xmlns:n0="http://www.examples.com/wsdl/MyService/">
<name i:type="d:string">Dave</name>
</n0:getPersonDetails>
</v:Body>
</v:Envelope>
BUT..SoapUI only accepts the following as a valid XML request :
<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>
<getPersonDetails>
<name>Dave</name>
</getPersonDetails>
</v:Body>
</v:Envelope>
For some reason, it doesn't like the xmlns="http://www.examples.com/getPersonDetails/" id="o0" c:root="1"
part, but I can't find a way to remove it, please help!
So how can I completely remove the xmlns declaration? It feels "dirty" creating a SoapObject and setting namespace to ""
Play with
envelope.implicitTypes = true;
as well as
envelope.setAddAdornments(false);
and see if you get it to do what you want. Also keep in mind that in the end the request is totally valid and it will depend on your server if it is okay with it and NOT SoapUI.