The program should form a SOAP request using the specified pattern:
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="urn:General.Intf-IGeneral" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://www.w3.org/2003/05/soap-encoding"><env:Body><ns1:Login env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"><UserName xsi:type="xsd:string"></UserName><Password xsi:type="xsd:string"></Password><IP xsi:type="xsd:string"></IP></ns1:Login></env:Body></env:Envelope> But at the exit:
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="urn:General.Intf-IGeneral" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://www.w3.org/2003/05/soap-encoding"><env:Body><n0:Login xmlns:n0=""http://www.w3.org/2003/05/soap-encoding""><UserName xsi:type="xsd:string">John</UserName><Password xsi:type="xsd:string">Candy</Password><IP xsi:type="xsd:string">192.168.1.1</IP></n0:Login></env:Body></env:Envelope> The tag difference is correct:
<ns1:Login env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"> And wrong:
<n0:Login xmlns:n0="http://www.w3.org/2003/05/soap-encoding"> The CustomSoapSerializationEnvelope class has been created, where 2 write and writeBody methods are redefined:
public class CustomSoapSerializationEnvelope extends SoapSerializationEnvelope{ public final String ns1="urn:General.Intf-IGeneral"; public final String encodingStyle="http://www.w3.org/2003/05/soap-encoding"; public CustomSoapSerializationEnvelope(int version) { super(version); } @Override public void write(XmlSerializer writer) throws IOException { super.addAdornments=false; super.dotNet=false; writer.setPrefix("env",env); // <-- changed line writer.setPrefix("ns1", ns1 ); writer.setPrefix("xsd",xsd); writer.setPrefix("xsi",xsi); writer.setPrefix("enc",enc); writer.startTag(env, "Envelope"); writer.startTag(env, "Body"); writeBody(writer); writer.endTag(env, "Body"); writer.endTag(env, "Envelope"); } public void writeBody(XmlSerializer writer) throws IOException { if (encodingStyle != null) { writer.attribute(env, "encodingStyle", encodingStyle); } ((Node) bodyOut).write(writer); }} Compile error:
java.lang.ClassCastException: org.ksoap2.serialization.SoapObject cannot be cast to org.kxml2.kdom.Node
Snippet where the packet is formed and the request is created:
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("UserName","John") .addProperty("Password","Candy") .addProperty("IP","192.168.1.1"); //Declare the version of the SOAP request CustomSoapSerializationEnvelope envelope = new CustomSoapSerializationEnvelope(CustomSoapEnvelop.VER12); envelope.setOutputSoapObject(request); //Needed to make the internet call HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); try { //this is the actual part that will call the webservice androidHttpTransport.call(SOAP_ACTION, envelope); } catch (Exception e) { e.printStackTrace(); } // Get the SoapResult from the envelope body. SoapObject result = (SoapObject)envelope.bodyIn;