How to create proper soap envelope (request xml) in code while using KSoap2?

喜你入骨 提交于 2019-11-29 11:40:24
Dexter

Well finally I got it working after some more research and got the answers to the questions.

1) Though SoapUi genearted <soapenv:Envelope xmlns:soapenv="...." ....> type response xml and android code using Ksoap2 library genearted <v:Envelope xmlns:i="..." ...> type response xml have different looking tags, it is not significant in getting errors. Both are similar.

As mentioned on the answer to SO question, ksoap has hardcoded values for the namespace in SoapEnvelope.

2) The unrecognized operation exception was due to issue in the MAIN_REQUEST_URL and NAMESPACE. Knowing the proper value of url, namespace and the soap_action is bit tricky, at least for a beginner in this space.

The values of these fields can be set by looking at the request/response xml, wsdl and this nice pictorial example.

In my case, I had to change

MAIN_REQUEST_URL = "http://abc.xyz.com/WSClient/WSServiceSoapHttpPort";
NAMESPACE = "http://wsclient.xyz.com//";
SOAP_ACTION = "http://wsclient.xyz.com//loginservice";

to

MAIN_REQUEST_URL = "http://abc.xyz.com/WSClient/WSServiceSoapHttpPort?WSDL";
NAMESPACE = "http://wsclient.xyz.com/types/";
SOAP_ACTION = "http://wsclient.xyz.com//loginservice";

and also I had to change:

String methodname = "loginservice";

to

String methodname = "loginserviceElement";

as the request/response xml has this ( typ:loginserviceElement ) tag wrapping the properties/parameters.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!