Android, KSoap2 and .NET Web Service w/ parameters = NULL result

后端 未结 5 1100
情书的邮戳
情书的邮戳 2021-01-12 23:00

Apparently this is a fairly often experienced issue. I\'m not sure entirely where the problem lies, or what needs to be adjusted, but for the life of me I cannot retrieve an

相关标签:
5条回答
  • 2021-01-12 23:21

    That might be not the answer you'd like to hear, but, generally, if I were in your shoes, I'd consider switching away from SOAP (to REST-style web service, for example).

    There are myriads of articles criticizing SOAP (and WSDL, and UDDI) floating around - you've probably seen some of them, such as 1, 2, 3 - and, indeed, they're a bit old, but still very true. You're experiencing now exactly what's SOAP being criticized much about - utter complexity and general incompatibility of various implementations - especially cross-platform.

    0 讨论(0)
  • 2021-01-12 23:28

    Wow. Chalk this one up to all sorts of oddities and oversights, but I've fixed it.

    The problem was the missing trailing '/' at the end of the namespace. NOT the namespace declared for the Android globals, but the namespace declared on the Web Service itself near the top of the service.asmx.cs file. (Directly above WebServiceBinding).

    Once I added it to the end, everything was functioning like a champ.

    Oddly enough, this obviously affects ONLY methods that take parameters as those methods without parameters were working perfectly. And only with KSoap2 as my web site that uses the exact same services was functioning flawlessly.

    0 讨论(0)
  • 2021-01-12 23:31

    In You DOT NET WEB SERVICE see the function below:

    [SoapRpcMethod]
    [WebMethod]
    public Complex GetComplex(string Name)
    {
        Complex myObj = new Complex();
        if (Name == "" || Name == null ) Name = "empty param";
        myObj.name = "Return FRom My " + Name;
        myObj.value = 888;
        return myObj;
    }
    

    WHEN YOU USE [SoapRpcMethod] because of return Complex type. IN YOUR JAVA Programe:

    SoapObject rpc4 = new SoapObject(serviceNamespace, "GetComplex");
    
    rpc4.addProperty("Name", "Johnson TONG");
    

    Below codes are also working too

    PropertyInfo pi = new PropertyInfo();
    pi.name= "Name";
    pi.type = PropertyInfo.STRING_CLASS;
    
    rpc4.addProperty(pi, "Johnson");
    
    int MyCount = rpc4.getPropertyCount();
    SoapSerializationEnvelope envelope4 = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope4.bodyOut = rpc4;
    envelope4.dotNet = false; // <--
    

    Don't ever use envelope4.dotNet = true this will always passing null value to the Server for reason that I don't know.

    envelope4.setOutputSoapObject(rpc4);
    envelope4.addMapping("http://tempuri.org/encodedTypes", "Complex", new Complex().getClass());
    HttpTransport ht4 = new HttpTransport(serviceUrl);
    ht4.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    ht4.debug = true;
    
    0 讨论(0)
  • 2021-01-12 23:42

    I have noticed a problem with boolean params. I noticed that your code doesn't have any currently, but this is just a heads up. I just changed the booleans to ints

    0 讨论(0)
  • 2021-01-12 23:46

    in my case, I lost much time trying to use SOAP, I had many errors, until you use REST.

    This link leads to a tutorial for using REST

    http://programmerguru.com/android-tutorial/android-restful-webservice-tutorial-how-to-call-restful-webservice-in-android-part-3/

    0 讨论(0)
提交回复
热议问题