Friday, 15 August 2014

xml - Android SOAP envelope modification -



xml - Android SOAP envelope modification -

the application creates next request xml:

<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> body... </v:body> </v:envelope>

and need prepare kind of request:

<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" 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/"> <soapenv:header/> <soapenv:body> body... </soapenv:body> </soapenv:envelope>

the of import in first string, should start xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" instead of xmlns:i="http://www.w3.org/2001/xmlschema-instance"

how alter in:

try { soapobject request = new soapobject(namespace, method_name); request.addproperty("entity", "persona"); request.addproperty("last_update_date", "20140101"); request.addproperty("country", "ua"); request.addproperty("user", "someuser"); soapserializationenvelope envelope = new soapserializationenvelope(soapenvelope.ver11); log.i(tag, "envelope string: \n" + string.valueof(envelope)); log.i(tag, "request string: \n" + string.valueof(request)); envelope.implicittypes = true; envelope.setaddadornments(false); envelope.dotnet = true; envelope.bodyout = request; envelope.setoutputsoapobject(request); httptransportbasicauth androidhttptransport = null; seek { androidhttptransport = new httptransportbasicauth(url, null, null); androidhttptransport.debug = true; androidhttptransport.call(soap_action, envelope); soapobject result = (soapobject) envelope.getresponse(); } grab (soapfault e) { e.printstacktrace(); log.d(tag, "2 http request:\n" + androidhttptransport.requestdump); log.d(tag, "2 http response:\n" + androidhttptransport.responsedump); } grab (exception e) { e.printstacktrace(); soapobject resultsrequestsoap = (soapobject)envelope.bodyin; log.d(tag, "exception request:\n" + androidhttptransport.requestdump); log.d(tag, "bodyin #2 \n" + resultsrequestsoap); log.d(tag, "exception response:\n" + androidhttptransport.responsedump); } } grab (exception e) { e.printstacktrace(); } }

this logcat trace:

06-25 12:50:58.955: i/envelope_body(24323): xmldataget{property1=value1; property2=value2; property3=value3; property4=value4; } 06-25 12:50:59.630: d/getinfo(24323): exception request: 06-25 12:50:59.630: d/getinfo(24323): <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><xmldataget xmlns="http://tempuri.org/"><property1>value1</property1><property2>value2</property2><property3>value3</property3><property4>value4</property4></xmldataget></v:body></v:envelope> 06-25 12:50:59.635: d/getinfo(24323): bodyin 06-25 12:50:59.635: d/getinfo(24323): null 06-25 12:50:59.635: d/getinfo(24323): exception response: 06-25 12:50:59.635: d/getinfo(24323): <s:envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/"><s:body xmlns:xsi="https://www.w3.org/2001/xmlschema-instance" xmlns:xsd="https://www.w3.org/2001/xmlschema"><xmldatagetresponse xmlns="https://tempuri.org/"><xmldatagetresult><itemlist xmlns="">....the whole info structure...</itemlist></xmldatagetresult></xmldatagetresponse></s:body></s:envelope> 06-25 12:57:26.500: w/system.err(25523): org.xmlpull.v1.xmlpullparserexception: expected: start_tag {http://schemas.xmlsoap.org/soap/envelope/}envelope (position:start_tag <{https://schemas.xmlsoap.org/soap/envelope/}s:envelope>@1:66 in java.io.inputstreamreader@42832a90)

logs after envelope construction:

07-07 15:15:22.296: i/getinfo(29392): envelope string: 07-07 15:15:22.296: i/getinfo(29392): org.ksoap2.serialization.soapserializationenvelope@42602660 07-07 15:15:22.296: i/getinfo(29392): request string: 07-07 15:15:22.296: i/getinfo(29392): xmldataget{entity=persona; last_update_date=20140101; country=ua; user=someuser; }

android xml soap

No comments:

Post a Comment