Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
imin
Posts: 3
Registered: ‎12-13-2011
My Carrier: 60132906603

ksoap2 send parameters as xml string

i'm stuck with this in the past few days... my soap requestformat should look like this

<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:Body>< WsAbcMobileAcctInq xmlns="http://tempuri.org/"><xml_var><HCMSG xmlns=""> <ABC><ABCTRANSID>MOBL</ABCTRANSID></ABC><REF><TXNTYPE>INQ</TXNTYPE><SC_CD>000ACD</SC_CD> <REFNO>MOBL0000000060018987941MAT</REFNO></REF><FIXPART><TXNDATE>20110105</TXNDATE> <TXNTIME>11464178</TXNTIME><AGN_CD>000000006001</ AGN_CD ></FIXPART><VARPART> <AC_NO TYP="N">0000000000008946565</AC_NO> <IC_NO TYP="N">0008956466546</ IC_NO><ID_CD TYP="S">IN</ ID_CD> </VARPART></HCMSG></xml_var></ WsAbcMobileAcctInq></soap:Body></soap:Envelope> 

how do I do it using blackberry and ksoap? this is what i did so far, but without success

SoapObject rpc = new SoapObject(serviceNamespace, "HelloServer"); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.headerOut = new Element[1]; envelope.headerOut[0] = buildAuthHeader(); envelope.bodyOut = rpc; envelope.dotNet = true; envelope.encodingStyle = SoapSerializationEnvelope.XSD; rpc.addProperty("msg", (new Date()).toString()); envelope.bodyOut = rpc; envelope.dotNet = true; envelope.encodingStyle = SoapSerializationEnvelope.XSD; rpc.addProperty("msg", (new Date()).toString()); HttpTransport ht = new HttpTransport(serviceUrl); ht.debug = true; String result; try { ht.call(soapAction, envelope); result = (envelope.getResponse()).toString(); System.out.println("resultttt:" + result); } catch(Exception ex) { result = ex.toString(); // do something with this later. System.out.println("resultttterror:" + result); } 

and here's the buildAuthHeader function:

private Element buildAuthHeader() { String sMobileXml = '<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:Body>< WsAbcMobileAcctInq xmlns="http://tempuri.org/"><xml_var>' + '<HCMSG xmlns=""><ABC><ABCTRANSID>MOBL</ABCTRANSID></ABC><REF><TXNTYPE>INQ</TXNTYPE><SC_CD>000ACD</SC_CD>< REFNO>MOBL0000000060018987941MAT</REFNO></REF><FIXPART><TXNDATE>20110105</TXNDATE>' +'<TXNTIME>11464178</TXNTIME><AGN_CD>000000006001</ AGN_CD ></FIXPART><VARPART>' +'<AC_NO TYP="N">0000000000008946565</AC_NO>' +'<IC_NO TYP="N">0008956466546</ IC_NO><ID_CD TYP="S">IN</ ID_CD>' +'</VARPART></HCMSG></xml_var></ WsAbcMobileAcctInq></soap:Body></soap:Envelope>'; Element h = new Element().createElement(NAMESPACE, "AuthHeader"); Element username = new Element().createElement(NAMESPACE, "sMobileXml"); username.addChild(Node.TEXT, sMobileXml); h.addChild(Node.ELEMENT, username); return h; }
Please use plain text.
New Contributor
imin
Posts: 3
Registered: ‎12-13-2011
My Carrier: 60132906603

Re: ksoap2 send parameters as xml string

instead of the method i'm using above, i'm thinking sending the soaprequest as xml string.. as suggested by post no#5 in this thread http://supportforums.blackberry.com/t5/Java-Development/Ksoap2-complex-data-types/m-p/1456563#M18519... .. because i faced the same prob when developing an android apps, and sending the whole parameters as xml string solves the problem.. but I donno how to do it in blackberry
Please use plain text.
Developer
sheeluwiki
Posts: 254
Registered: ‎03-15-2011
My Carrier: simulator

Re: ksoap2 send parameters as xml string

for complex requests you have to create a class that implements KvmSerializable ..

 

Refer this link for a small example

http://supportforums.blackberry.com/t5/Java-Development/KSOAP2-Complex-type-containing-complex-type-...

------------------------------------------------------------------------------------------------
Click "Accept as Solution" if post was what you needed. Give kudos if you feel response is helpful.

Please use plain text.