Android ksoap2参数问题

发布于 2024-12-10 18:51:40 字数 1079 浏览 1 评论 0原文

我试图将参数传递给我的服务,代码运行但服务从未收到参数?调用有效,我只需添加变量然后将其取回,当取回它时,我发现网络服务从未收到它!

感谢您的帮助

    final String SOAP_ACTION = "http://NathofGod.com/GetCategoryById";
    final String METHOD_NAME = "GetCategoryById";
    final String NAMESPACE = " http://NathofGod.com/";
    final String URL = "http://10.0.2.2:4021/Service1.asmx";

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

 PropertyInfo pi1 = new PropertyInfo();
        pi1.setName("name");
        pi1.setValue("the name");
        pi1.setType(String.class);
        pi1.setNamespace(NAMESPACE);
        request.addProperty(pi1);

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

       HttpTransportSE conn = new HttpTransportSE(URL);

        try
        {
            conn.call(SOAP_ACTION, envelope);
            SoapObject response = (SoapObject)envelope.getResponse();
        }

        catch(Exception e)
        {
            e.printStackTrace();
        }

I am trying to pass a parameter to my service, the code runs but the service never receives the parameters?? The call works, I simply add the variable then get it back, when getting it back I discover the webservice never received it!

Thanks for your help

    final String SOAP_ACTION = "http://NathofGod.com/GetCategoryById";
    final String METHOD_NAME = "GetCategoryById";
    final String NAMESPACE = " http://NathofGod.com/";
    final String URL = "http://10.0.2.2:4021/Service1.asmx";

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

 PropertyInfo pi1 = new PropertyInfo();
        pi1.setName("name");
        pi1.setValue("the name");
        pi1.setType(String.class);
        pi1.setNamespace(NAMESPACE);
        request.addProperty(pi1);

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

       HttpTransportSE conn = new HttpTransportSE(URL);

        try
        {
            conn.call(SOAP_ACTION, envelope);
            SoapObject response = (SoapObject)envelope.getResponse();
        }

        catch(Exception e)
        {
            e.printStackTrace();
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

呆萌少年 2024-12-17 18:51:40

不确定为什么不起作用,但我记得使用它

request.addProperty("name", "my_Name");

并且工作正常,否则你可能想检查服务器端......

not sure about why is not working, but I remember using it with

request.addProperty("name", "my_Name");

and it worked fine, otherwise you may wanna check the server side...

御弟哥哥 2024-12-17 18:51:40

这行代码是我的问题!!!

envelope.dotNet = true;

删除它

This line of code was my issue!!!

envelope.dotNet = true;

REMOVE IT

子栖 2024-12-17 18:51:40

尝试按照说明进行调试在维基上

Try to debug it following the instructions on the wiki.

那一片橙海, 2024-12-17 18:51:40

我稍微清理了一下代码并将其放入一个函数中。我不确定是否有什么不同,但这段代码可以工作。感谢您的回复。

public SoapObjectsoap() 抛出 IOException、XmlPullParserException
{

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
    request.addProperty("name", "myname"); 
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request); 
    HttpTransportSE conn = new HttpTransportSE(URL);

    conn.call(SOAP_ACTION, envelope); //send request
    SoapObject result=(SoapObject)envelope.getResponse(); 
    return result;
 }

I cleaned up the code a little and put it in a function. I'm not sure if something is different but this code works. Thanks for the responses.

public SoapObject soap() throws IOException, XmlPullParserException
{

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
    request.addProperty("name", "myname"); 
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request); 
    HttpTransportSE conn = new HttpTransportSE(URL);

    conn.call(SOAP_ACTION, envelope); //send request
    SoapObject result=(SoapObject)envelope.getResponse(); 
    return result;
 }
滴情不沾 2024-12-17 18:51:40

最终字符串 NAMESPACE = " http://NathofGod.com/";

更改为

final String NAMESPACE = "http://NathofGod.com/";

删除空白并按照请求 XML 上的方式创建命名空间。请注意,它也区分大小写。

final String NAMESPACE = " http://NathofGod.com/";

Change to

final String NAMESPACE = "http://NathofGod.com/";

Remove the empty space and make then namespace as it is on your request XML. Please note that it is case sensitive as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文