KSOAP调用.NET ASMX服务传递空参数 [英] KSoap calling .NET ASMX service passing null arguments

查看:309
本文介绍了KSOAP调用.NET ASMX服务传递空参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打电话给使用KSOAP从Android应用程序一个ASMX服务。它有两个参数,这两个字符串类型。当从.NET应用程序把它称为succeds但是当从Android应用程序Web服务调用变得空白的参数,我不明白为什么。

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 ..

下面是code为同一

            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 {

            }

我用小提琴手看到bwtween Visual Studio和Eclipse调用的区别,发现两者生成调用不同的XML,不明白我怎么能做出KSOAP发送正确

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

由Visual Studio呼叫 -

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>

从Eclipse中的Andr​​oid项目呼叫

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.

推荐答案

只是为了确保如果有其他人停留在相同的情况下,需要的支持,在这里就是答案。

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


  1. 初始化参数以使用的PropertyInfo类例如通过。

  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);


  • 下面设置在同一序列(听起来可能很傻,但是这是我的问题是,如何解决)

  • 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;
    


  • 希望它帮助!

    这篇关于KSOAP调用.NET ASMX服务传递空参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆