gpt4 book ai didi

android - KSoap 调用 .NET ASMX 服务传递空参数

转载 作者:行者123 更新时间:2023-11-30 03:45:37 26 4
gpt4 key购买 nike

我正在尝试使用 KSoap 从 Android 应用程序调用 ASMX 服务。它接受两个参数,都是字符串类型。当从 .NET 应用程序调用时它成功了但是当从 Android 应用程序 web 服务调用时得到空白参数,我不明白为什么..

这是相同的代码

            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 {

}

我使用 Fiddler 查看 Visual Studio 和 Eclipse 调用之间的区别,发现两者都为调用生成不同的 xml,不明白如何让 Ksoap 发送正确的 xml

通过 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 Android 项目中调用

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

任何指针都会有很大的帮助。

最佳答案

只是为了确保其他人是否陷入同样的​​境地并需要支持,这里是答案。

  1. 使用 PropertyInfo 类初始化要传递的参数,例如

    PropertyInfo loginProcPI = new PropertyInfo();
    // loginProcPI.setNamespace(NAMESPACE);
    loginProcPI.setName("MobileNo");
    loginProcPI.setValue("0123456789");
    loginProcPI.setType(String.class);

    request.addProperty(loginProcPI);
  2. 以相同的顺序设置以下两个属性(听起来可能很傻,但这就是我的问题得到解决的方式)

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

希望对您有所帮助!

关于android - KSoap 调用 .NET ASMX 服务传递空参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15052001/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com