SoapObject Add property xml string in Webservice using ksoap2 - android

I created XML string using XmlSerializer and it prints out as
<tag> string </tag>
I want to add the xml string to SOAPObject and get response from web service.
So I added and when I print out the requestDump the < and > are being replaced by &lt ; and &gt ;
I assume that it is being encoded by HttpTransportSE.
I read here Android Ksoap2 web service for download/Upload and it says I need to convert my string to binary before uploading? I am confused because the API tells us to upload xml. Currently, there is no error or exception but the result is empty. I think it's the encoding problem.
Any help will be appreciated. Thanks!

When using ksoap2 you don't have to handle the serialization yourself. If you want to add an entry to the xml like this:
<tag>string</tag>
Then you just have to call this when constructing the SoapObject you are sending to the server:
soapObject.addProperty("tag", "string");
Also modifying the requestDump is never a good idea. This output is just for debug purposes. That's the reason why you have to set transport.debug = true; for the requestDump or responseDump to even appear. As I said above just use the addProperty() and addSoapObject() methods to construct your request.

Use SoapObject.setInnerText("..."); to add CDATA text to a Ksoap2 request.

Related

Special character coming parsing the xml

When I am parsing xml, I am getting special in good dynamics application char like that
pic.png
but the actual text is like that "If you've got any question or need"
But when I am parsing same text in normal application its working fine.
I am using sharepoint server to get xml. Now I am using general encoding UTF-8 only.
For parsing I am using XMLpullparser.
So how to resolve special character from xml.
There might be two things you might check:
Persister class used to parse the .xml can be initialised with such constructor:
Persister persister = new Persister(new Format(4, "<?xml version=\"1.0\" encoding= \"UTF-8\" ?>"));
You might replace all such characters while parsing:
value = value.replace("'", "\\'");

StringBuilder append String breaks UTF 8

Im sending an XML with HttpPost to a server. This used to wotk fine, and im doing it succesfully in other parts of the project.
Im using a StringBuilder to create the xml request but since i am appending strings as Data to the nodes, i am getting an error response from the parser on the server:
Invalid byte 2 of 2-byte UTF-8 sequence.
When i log the request and check it in w3c xml validator there are no errors.
This is an excerpt (whole method would be to big and has sensitive Data) from my Stringbuilder Method:
StringBuilder baseDocument = new StringBuilder();
baseDocument.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><request><setDisposalRequest><customer><company><![CDATA[");
baseDocument.append(company);
baseDocument.append("]]></company>");
baseDocument.append("<firstName><![CDATA[");
baseDocument.append(name);
baseDocument.append("]]></firstName>");
...
As soon as i replace the String vars i append with hardcoded Strings, all works fine
i.e
baseDocument.append(name);
to
baseDocument.append("name");
All the strings have values, non of them a null or are empty!
Before the request i set the StringEntity to xml
se.setContentType("application/xml");
what am i missing?!?
Your XML header claims that it's UTF-8, yet you never mention if you actually write UTF-8. Make sure the actual bytes you send are UTF-8 encoded. The error message suggests that you're using another encoding (probably a ISO-8859-* variant).
This is another reason that manually constructing XML like this is dangerous: there are just too many corner cases to observe and it's much easier to use a real XML handling library. Those tend to get the corner cases correct ;-)
And no: StringBuilder certainly does not break UTF-8. The problem is somewhere else.

how to get the values from soap response in android?

the following xml tag for webservice response ,i dont know how to parse it..help me..
<NewDataSet>
<JOBLIST>
<CSIDNO>CS13224</CSIDNO>
<PName>Selva</PName>
<HouseID>G 34</HouseID>
<NAME>Dilipan</NAME>
<Address>Coimbatore</Address>
</JOBLIST>
<JOBLIST>
<CSIDNO>CS13224</CSIDNO>
<PName>Selva</PName>
<HouseID>G 35</HouseID>
<NAME>Kanrupannan</NAME>
<Address>Coimbatore</Address>
</JOBLIST>
</NewDataSet>
i am using the following java code .....
for(int i=0;i<result.getPropertyCount();i++)
{
SoapObject ob=(SoapObject)result.getProperty(i);
homeid[i]=String.valueOf(ob.getProperty("HouseID"));
namearr[i]=String.valueOf(ob.getProperty("NAME"));
address[i]=String.valueOf(ob.getProperty("Address"));
csidno[i]=String.valueOf(ob.getProperty("CSIDNO"));
}
how to get the values form xml tag..
Why using Soap there are different kinds of parsing methods you can use one of them. Parsing methods are SAXParser, Json parser, DOM parser, XML pull parser. In yourt situation SAX parser will be good to parse. see this and this tutorial. It will help you in parsing the xml you are receiving. Let me know if they helps you
Its pretty simple you have to get the respose as a string and use pattern matches to extract the detail you needed>Please see this post hope it helps you and you understand it.
String r = NameArray.columncount("userid", limitstart, loadNumber,loggername);
String temp = r.replaceAll(";\\s", ",").replaceAll("string=", " ")
.replace("anyType{", "").replace(",}", "");
enter code here
check this link for step by step instruction
http://amalan008.blog.com/2013/02/07/how-to-process-an-array-returned-by-a-wsdl-android/

Android make xml node for Soap Parameter

a Dot net Webservice is expecting an XML node as a parameter:
The string that it would deserialize to is:
"<Service PTA="" QSF="" xmlns="" />";
I have floundered around trying to make a serializable class with a public string of:
"<Service PTA=\"\" QSF=\"\" xmlns=\"\" />";
But I get errors of 'Cannot Serialize' from:
androidHttpTransport.call(SOAP_ACTION, envelope);
What is the best way to do this?
thanks
Its a Kludge but it works. using KSOAP2 library.
Adding a xml node to SoapObject request, parameter myParam
String xml = "<Service PTA=\"\" QSF=\"\" xmlns=\"\" />";
request.addProperty("myParam>"+xml,"")
Not ideal but...

Web Service with Android KSoap returns anyType

I am currently doing an Andrid project which deals with the clients webservice. To cut the story short, when running the webservice as a test, the browser displays proper well formed XML but on the Android KSoap it returns AnyType{resp=200; etc etc} so I found out that the httpTransport.debug = true has to be on and using httpTransport.responseDump and it will form full XML including the HTML tags such as
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/
and so on, but this is not the case from the browser and I need the browser's output format.
Am I suppose to do something else?
transport.call(soap_action, envelope);
result = (SoapObject) envelope.getResponse();
result.getProperty(0).toString();//will give you first element of returned objects

Categories

Resources