Android ksoap2 parameter issues

為{幸葍}努か 提交于 2019-12-25 04:05:47

问题


I am trying to pass a parameter to my service, the code runs but the service never receives the parameters?? The call works, I simply add the variable then get it back, when getting it back I discover the webservice never received it!

Thanks for your help

    final String SOAP_ACTION = "http://NathofGod.com/GetCategoryById";
    final String METHOD_NAME = "GetCategoryById";
    final String NAMESPACE = " http://NathofGod.com/";
    final String URL = "http://10.0.2.2:4021/Service1.asmx";

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

 PropertyInfo pi1 = new PropertyInfo();
        pi1.setName("name");
        pi1.setValue("the name");
        pi1.setType(String.class);
        pi1.setNamespace(NAMESPACE);
        request.addProperty(pi1);

 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);

       HttpTransportSE conn = new HttpTransportSE(URL);

        try
        {
            conn.call(SOAP_ACTION, envelope);
            SoapObject response = (SoapObject)envelope.getResponse();
        }

        catch(Exception e)
        {
            e.printStackTrace();
        }

回答1:


not sure about why is not working, but I remember using it with

request.addProperty("name", "my_Name");

and it worked fine, otherwise you may wanna check the server side...




回答2:


This line of code was my issue!!!

envelope.dotNet = true;

REMOVE IT




回答3:


Try to debug it following the instructions on the wiki.




回答4:


I cleaned up the code a little and put it in a function. I'm not sure if something is different but this code works. Thanks for the responses.

public SoapObject soap() throws IOException, XmlPullParserException {

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
    request.addProperty("name", "myname"); 
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request); 
    HttpTransportSE conn = new HttpTransportSE(URL);

    conn.call(SOAP_ACTION, envelope); //send request
    SoapObject result=(SoapObject)envelope.getResponse(); 
    return result;
 }



回答5:


final String NAMESPACE = " http://NathofGod.com/";

Change to

final String NAMESPACE = "http://NathofGod.com/";

Remove the empty space and make then namespace as it is on your request XML. Please note that it is case sensitive as well.



来源:https://stackoverflow.com/questions/7814164/android-ksoap2-parameter-issues

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