如何在Android Web服务中将数组作为soap对象发送
首先,我要感谢 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯……有很多地方可能有问题。我将尝试解释如何检测这些位置并调试您的代码:
以这种方式记录您的请求和响应:
而且......我不确定,但尽量不要使用向量并按顺序添加数组属性:
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:
Log your request and response this way:
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!