KSOAP2库...错误将数据发送到ASMX web服务 [英] KSOAP2 Library...Error sending data to asmx webservice

查看:161
本文介绍了KSOAP2库...错误将数据发送到ASMX web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在微软的Azure的ASMX web服务的设置和我试图将数据发送到Web服务,并使用Android应用程序接收输出。为此,我现在用的是KSOAP库。

I have an ASMX webservice setup on Microsoft Azure and I'm trying to send data to the webservice and receive output using an android application. For this purpose, I am using the KSOAP library.

在web服务,我检查,如果字符串为null。如果是这样,我返回一个错误code2405

On the webservice, I'm checking if the strings are null. If they are, I return an error code "2405"

[WebMethod]
        public string LoginUser(string auth_token, string username)
        {
            // All these tests performed, so someone from outside of out application
            // scope does not attempt to abuse our webservice.
            #region Check for nulls
            if (string.IsNullOrEmpty(auth_token))
                return "2405";
            if (string.IsNullOrEmpty(username))
                return "2405";
            #endregion
        }

在我的Andr​​oid应用程序,我送了数据,但web服务仍返回2405错误code,这意味着数据不会被发送。

In my android application, I am sending the data, but the webservice still returns the 2405 error code, which means that the data is not sent.

以下是我的Andr​​oid code:

The following is my android code:

        SoapObject request = new SoapObject(NAMESPACE, method_name);

        PropertyInfo pi = new PropertyInfo();
        pi.setName("auth_token");
        pi.setValue("TestAuth");
        request.addProperty(pi);

        PropertyInfo pe = new PropertyInfo();
        pe.setName("username");
        pe.setValue("TestUser");
        request.addProperty(pe);

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

        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.call(SOAP_ACTION, envelope);

对不起,我可以为您提供空间,方法名,网址等,这是对公司政策,我希望你能理解。 :)

Sorry that I can provide you with the namespace, methodname, url, etc. It is against the company policy and I hope you understand. :)

不过,我会再看一遍错误。调用以上的Andr​​oid code后,Web服务将返回2405,而根据ASMX code是当任何三三两两值为null。

更新:我​​调试的SOAP请求(androidHttpTransport.debug = TRUE),得到以下结果为requestDump和responseDump

Nevertheless, I'll go over the error again. After calling the above Android code, the webservice returns 2405, which according to the ASMX code is when any of the twos values are null.

UPDATE: I debugged the SOAP request (androidHttpTransport.debug = true) and got the following results for the requestDump and responseDump.

请求转储

<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>
    <LoginUser xmlns="http://tempuri.org" id="o0" c:root="1">
      <auth_token i:type="d:string">TestAuth</auth_token>
      <username i:type="d:string">TestUser</username>
    </LoginUser>
  </v:Body>
</v:Envelope>

responseDump

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <LoginUserResponse xmlns="http://tempuri.org/">
      <LoginUserResult>2405</LoginUserResult>
    </LoginUserResponse>
  </soap:Body>

</soap:Envelope>

更新2
这是服务器期望:

UPDATE 2
This is what the server expects:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <LoginUser xmlns="http://tempuri.org/">
      <auth_token />
      <username />
    </LoginUser>
  </soap:Body>
</soap:Envelope>

这是什么 Android应用程序发送

This is what the android application is sending:

<?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>
        <LoginUser xmlns="http://tempuri.org" id="o0" c:root="1">
            <auth_token i:type="d:string">TestAuth</auth_token>
            <username i:type="d:string">TestUser</username>
        </LoginUser>
    </v:Body>
</v:Envelope>

在除了这个,我已经添加了下面一行到Android code:

In addition to this, I've added the following line to the android code:

androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");

请帮助!

非常感谢!

推荐答案

我是能够清除错误...问题是,我没有足够的空间后,一个反斜杠URI ......我没有理由 t是与反斜杠我有序列不包含任何元素的错误...但是现在,我有不同的错误......如果我需要帮助,我会后在计算器...感谢您的慷慨帮助:)

I was able to clear the error...The problem was that I didn't have a backslash after the namespace URI...The reason I didn't is that with the backslash I got the error "Sequence contains no elements"...Now, however, I'm having different errors...If I need help I'll post on StackOverFlow...Thanks for the generous help :)

需要明确的是,该命名空间的必须有AA反斜杠结束,为了使服务器接收任何参数。

To be clear, the namespace must have a a backslash at the end, in order for the server to receive any parameters.

这篇关于KSOAP2库...错误将数据发送到ASMX web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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