KSoap calling .NET ASMX service passing null arguments

我的未来我决定 提交于 2020-01-03 01:59:24

问题


I am trying to call a ASMX service using KSoap from Android application. It accepts two parameters, both string type. When called from .NET application it succeds but when call from Android application webservice gets blank parameter, I dont understand why ..

Here is the code for the same

            static String NAMESPACE = "http://softco.org";
            static String URL_WS = "http://www.dummy.com/newservice.asmx";

            String GET_USER_DETAILS = "User_Verification";
            SoapObject request = new SoapObject(NAMESPACE, GET_USER_DETAILS);
            HttpTransportSE androidHttpTransport;

            // add parameters and values
            request.addProperty("MobileNo", String.valueOf("01234567899"));
            request.addProperty("Password", String.valueOf("abcdef"));

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);


            envelope.dotNet = true;
            envelope.encodingStyle = SoapSerializationEnvelope.XSD;
            envelope.setOutputSoapObject(request);

            // Web method call

            SoapObject result;

            try {
                androidHttpTransport = new HttpTransportSE(URL_WS);
                androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                androidHttpTransport.call(NAMESPACE + "/" + GET_USER_DETAILS, envelope);
                result = (SoapObject) envelope.getResponse();

                // get the response

                int propCnt = result.getPropertyCount();


                request = null;
                envelope = null;
                androidHttpTransport = null;

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (XmlPullParserException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } finally {

            }

I used Fiddler to see the difference bwtween Visual Studio and Eclipse calls and found both generates different xml for the call, dont understand how can I make Ksoap to send correct one

Call by Visual Studio -

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <User_Verification xmlns="http://softco.org/"><MobileNo xmlns="">01234567899</MobileNo><Password xmlns="">abcdef</Password></User_Verification></s:Body></s:Envelope>

Call from Eclipse Android project

    <?xml version="1.0" encoding="utf-8"?>
    <v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header />
    <v:Body><User_Verification xmlns="http://softco.org" id="o0" c:root="1"><MobileNo i:type="d:string">01234567899</MobileNo><Password i:type="d:string">abcdef</Password></User_Verification></v:Body></v:Envelope>

Any pointers would be a great help.


回答1:


Just to ensure if somebody else is stuck in same situation and needs support, here is the answer.

  1. Initialize your parameters to be passed using PropertyInfo class for e.g.

    PropertyInfo loginProcPI = new PropertyInfo();
    // loginProcPI.setNamespace(NAMESPACE);
    loginProcPI.setName("MobileNo");
    loginProcPI.setValue("0123456789");
    loginProcPI.setType(String.class);
    
    request.addProperty(loginProcPI);
    
  2. Set below two properties in the same sequence (may sound silly but that is how my issue is resolved)

    envelope.setAddAdornments(false);
    envelope.implicitTypes = true;
    

Hope it helps!




回答2:


i resolved using:

envelope.dotNet=true;

This is the source: http://articlesforprogramming.blogspot.com/2013/06/consume-net-webservice-in-android-using.html



来源:https://stackoverflow.com/questions/15052001/ksoap-calling-net-asmx-service-passing-null-arguments

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