Custom envelope

36 views
Skip to first unread message

Santi Prates

unread,
Aug 29, 2016, 10:37:01 PM8/29/16
to ksoap2-android
Hi Everyone, i have a problem and i can't fix it for now.

I need to create an envelope with custom parameters, the structure is realized with Elements and i put the object with .bodyOut property. The method  setOutputSoapObject is overriding my bodyOut for the Request object. 

I know that i have to pass the Request object, but, if i want to connect to a WS that receives an XML for paramater i cant, 

There is a way to fix that???

i have a code example:

 String SOAP_ACTION = "THE SOAP ACTION";
String METHOD_NAME = "THE METHOD NAME";
String NAMESPACE = "NAMESPACE";
String URL = "THE WEB SERVICE URL";

try
{


SoapObject Request = new SoapObject(NAMESPACE,METHOD_NAME);


Request.addProperty("usuario",usr);
Request.addProperty("clave",pass);
Request.addProperty("param3",rut);
Request.addProperty("param4","2");

SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);



//*************************************ENVELOPE HEADER**********************************************


//soapEnvelope.headerOut = null;


//**************************************ENVELOPE BODY***********************************************

// ROOT ELEMENT
Element Root = new Element();
SobreFactura.setNamespace(NAMESPACE);
SobreFactura.setName("ns:Root");




//Cabezal

Element Child1 = new Element();
Child1.setNamespace("");
Child1.setName("Child1");

Element Child11 = Child1.createElement("","Child11");
Child11.addChild(Node.TEXT,rut);
Child1.addChild(Node.ELEMENT,Child11);

Element Child12 = Child1.createElement("","Child12");
NumSobre.addChild(Node.TEXT,"1");
Cabezal.addChild(Node.ELEMENT,NumSobre);

Element Child13 = Child1.createElement("","Child13");
Child13.addChild(Node.TEXT,"content");
Child1.addChild(Node.ELEMENT,Child13);

/

Root.addChild(Node.ELEMENT,Child1);

soapEnvelope.xsi = "http://www.w3.org/2001/XMLSchema-instance";
soapEnvelope.xsd = "http://xxxxxxxxxx/soap/xxxxx";
soapEnvelope.enc = "http://www.w3.org/2001/12/soap-encoding";


soapEnvelope.bodyOut = new Element[] {Root};

soapEnvelope.encodingStyle = "UTF-8";

            soapEnvelope.setOutputSoapObject(Request); // IN THIS LINE THE bodyOut is override for the Request!!!! 


HttpTransportSE transport = new HttpTransportSE(URL);

transport.setXmlVersionTag("<?xml version='1.0' encoding='UTF-8'?>");

transport.debug=true;

transport.call(SOAP_ACTION,soapEnvelope);


response=(SoapObject) soapEnvelope.getResponse();


System.setProperty("http.keepAlive", "false");
}
catch (Exception ex)
{
Log.e(TAG, "Ex: "+ex.getMessage());
}


Reply all
Reply to author
Forward
0 new messages