java - Calling Soap webservice from android -
i using below process,
1)create string template soap request , substitute user-supplied values @ runtime in template create valid request. 2) wrap string in stringentity , set content type text/xml 3) set entity in soap request.
and of httppost posting request,
i using demo webservice w3schools.com
url--->
http://www.w3schools.com/webservices/tempconvert.asmx
what have tried is,
httppost httppost = new httppost("http://www.w3schools.com/webservices/tempconvert.asmx"); stringentity se; try { soaprequestxml="<soapenv:envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\"><soapenv:header/><soapenv:body><tem:celsiustofahrenheit><!--optional:--><tem:celsius>30</tem:celsius></tem:celsiustofahrenheit></soapenv:body></soapenv:envelope>"; log.d("request ", soaprequestxml+"!!!"); se = new stringentity(soaprequestxml,http.utf_8); se.setcontenttype("text/xml"); httppost.setheader("content-type","application/soap+xml;charset=utf-8"); httppost.setentity(se); httpclient httpclient = new defaulthttpclient(); basichttpresponse httpresponse = (basichttpresponse) httpclient.execute(httppost); httpentity resentity = httpresponse.getentity(); t.settext(entityutils.tostring(resentity)); } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); }
i able response in soapui, surely code wrong because in emulator getting output,
"the server cannot service request because media type unsupported".
am passing correct parameter in constructor of httppost or making correct xml request.i tried lot not figure out.
thanks
i have hunch emulator android version , phone version different.
but have few suggestions. use following:
httppost.setheader("accept-charset","utf-8"); httppost.setheader("accept","text/xml,application/text+xml,application/soap+xml");
similarly, set content type of above.
Comments
Post a Comment