如何在Android Web服务中将数组作为soap对象发送

发布于 2024-12-13 17:48:13 字数 1682 浏览 0 评论 0原文

首先,我要感谢 StackOverflow 及其所有成员在过去几个月对 android 的帮助。我的学习曲线很陡峭,我认为如果没有您的帮助我不会走到这一步。

我需要将数组作为肥皂对象发送到 Web 服务,但不断从服务器获得“空提交的 ID 列表”响应。我希望有人能告诉我原因。

我的代码如下:

public void FeedbackRead(String feedbackID) {
             String soapMethod = "feedbackRead";
             SoapObject request = new SoapObject(NAMESPACE, soapMethod);
             request.addProperty(getProperty("patientLogin", PATIENT_LOGIN));
             request.addProperty(getProperty("passwd", PATIENT_PASS));
             request.addProperty(getProperty("IDsRead", new String[]{feedbackID}));
             String res = doPost(request, soapMethod);           
             Log.i(soapMethod + "SOAP_RESPONSE ", res);
   }

PropertyInfo 方法是

private PropertyInfo getProperty(String name, String[] val) {
      PropertyInfo info = new PropertyInfo();
      info.name = name;
      info.namespace = NAMESPACE;
      info.type = PropertyInfo.VECTOR_CLASS;
      Vector<String> vct = new Vector<String>();
      for (int i = 0; i < val.length; i++)
         vct.add(val[i]);
      info.setValue(vct);
      return info;
   }

如何将字符串数组添加到请求 SoapObject 以便我可以将其发送到服务器?

好的,我知道肥皂对象属性应该是这样,因为我已经将它们打印到 logcat 并且它们应该是这样。我按照 logcat 粘贴到肥皂对象下面:

feedbackRead{patientLogin=patient1; passwd=pat1; IDsRead=[27d49cea-7968-457a-b377-7bd70bbca1a1, 27d49cea-7968-457a-b377-7bd70bbca1a2]; }

我要做的下一件事是

String res = doPost(request, soapMethod);

可能出了什么问题?

Res 始终包含消息:空提交的 ID 列表!

有什么方法可以对其进行转换,以便我可以将其粘贴到浏览器窗口中以查看它是否有效?或者这是一个完全愚蠢的问题?

非常感谢,

伊莱恩。

First of all, I have to thank StackOverflow and all its members for the past few months android help. My learning curve has been steep and I don't thiink I would have gotten this far without your help.

I need to send an array as a soap object to a web service but keep getting an "empty submitted ID list" response from the server. I am hoping someone can tell me why.

My code is as follows:

public void FeedbackRead(String feedbackID) {
             String soapMethod = "feedbackRead";
             SoapObject request = new SoapObject(NAMESPACE, soapMethod);
             request.addProperty(getProperty("patientLogin", PATIENT_LOGIN));
             request.addProperty(getProperty("passwd", PATIENT_PASS));
             request.addProperty(getProperty("IDsRead", new String[]{feedbackID}));
             String res = doPost(request, soapMethod);           
             Log.i(soapMethod + "SOAP_RESPONSE ", res);
   }

And the PropertyInfo method is

private PropertyInfo getProperty(String name, String[] val) {
      PropertyInfo info = new PropertyInfo();
      info.name = name;
      info.namespace = NAMESPACE;
      info.type = PropertyInfo.VECTOR_CLASS;
      Vector<String> vct = new Vector<String>();
      for (int i = 0; i < val.length; i++)
         vct.add(val[i]);
      info.setValue(vct);
      return info;
   }

How exactly should I add a string array to a request SoapObject so that I can send it to the server?

OK, I know that the soap objects properties are as should be because I have printed them to logcat and they are as should be. I am pasting below the soap object as per logcat:

feedbackRead{patientLogin=patient1; passwd=pat1; IDsRead=[27d49cea-7968-457a-b377-7bd70bbca1a1, 27d49cea-7968-457a-b377-7bd70bbca1a2]; }

The next thing i do is

String res = doPost(request, soapMethod);

What could possibly be going wrong?

Res always contains the message: empty submitted ID list!

Is there any way to convert it so I can paste it into my browser window to see does it work? Or is that a completely moronic question?

Thanks so much,

Elaine.

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

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

发布评论

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

评论(1

烟花肆意 2024-12-20 17:48:13

嗯……有很多地方可能有问题。我将尝试解释如何检测这些位置并调试您的代码:

  1. 以这种方式记录您的请求和响应:

     HttpTransportSE androidHttpTransport = new HttpTransportSE(serverUrl);
        androidHttpTransport.debug = true;
    
        androidHttpTransport.call(SOAP_ACTION, 信封);
    
        Log.d("测试", "请求:" + androidHttpTransport.requestDump);
        Log.d("测试", "响应:" + androidHttpTransport.responseDump);
    
  2. 将您的请求与正确的请求进行比较。为了获得正确的请求,你可能需要一些使用wsdl生成soap请求的工具(我使用soapUI,google一下。还有一个eclipse插件)。使用这样的工具,您可以向服务器发送正确的请求并检查服务器的方法是否有效。
  3. 而且......我不确定,但尽量不要使用向量并按顺序添加数组属性:

    request.addProperty(getProperty("IDsRead", FeedbackID1));
    request.addProperty(getProperty("IDsRead", FeedbackID2));
    request.addProperty(getProperty("IDsRead", FeedbackID3));

希望这有帮助。祝你好运!

Well... there are many places where something may be wrong. I'll try to explain how to detect these places and debug your code:

  1. Log your request and response this way:

        HttpTransportSE androidHttpTransport = new HttpTransportSE(serverUrl);
        androidHttpTransport.debug = true;
    
        androidHttpTransport.call(SOAP_ACTION, envelope);
    
        Log.d("test", "request: " + androidHttpTransport.requestDump);
        Log.d("test", "response: " + androidHttpTransport.responseDump);
    
  2. Compare your request with the correct request. To obtain the correct request you may need some tool that generate soap request using wsdl (I use soapUI, google it. Also there is a plugin for eclipse). Using such tool you can send correct request to the server and check whether server's methods work or not.
  3. And...I'm not sure but try not to use vector and add array properties sequentially:

    request.addProperty(getProperty("IDsRead", feedbackID1));
    request.addProperty(getProperty("IDsRead", feedbackID2));
    request.addProperty(getProperty("IDsRead", feedbackID3));

Hope this helps. Good luck!

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