是否可以通过 ksoap2 发送原始数组?
现在,无论我如何格式化请求属性,它都会收到:
Cannot Serialize: [int, int, int]
错误。我不知道还能尝试什么。我试过了:
ArrayList<Integer>, int[], Vector<Integer>, List<Integer>
这些都不起作用。我得到的最接近的是 Vector。它似乎已经很好地序列化了 Vector 对象,但是当我将其发送到 Web 服务方法时,我收到错误:
java.lang.RuntimeError Mismatched types
是的,我已将该方法的输入参数更改为 Vector并确保我导入了相同类型的向量。
这是我的 Web 服务和我的应用程序,因此,我确实拥有完整的范围。我愿意更改应用程序和 WS 的任何部分。如果您有任何想法请告诉我。这就是我创建 Web 服务请求的方式:
这是我尝试使用 Vector 的完整方法。
public ArrayList<Contacts> getLocationslist(Vector<Integer> list){
ArrayList<Contacts> contacts = new ArrayList<Contacts>();
String SOAP_ACTION = "urn:getLocationsList";
String METHOD_NAME = "getLocationsList";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("arg0", list);
SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
int i = 0;
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
while (i < resultsRequestSOAP.getPropertyCount()){
Contacts cont = new Contacts();
try {
Ksoap2ResultParser.parseBusinessObject(resultsRequestSOAP.getProperty(i).toString(), cont);
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
contacts.add(cont);
i = i + 1;
}
} catch (Exception e) {
e.printStackTrace();
}
return contacts;
}
我非常指望你!提前致谢。
Now matter how I format my request property, it get a:
Cannot Serialize: [int, int, int]
error. I have no clue what else to try. I've tried:
ArrayList<Integer>, int[], Vector<Integer>, List<Integer>
None of these worked. The one that I got the closest on was Vector.. It seemed to have serialized the Vector Objects fine, but when I sent it to the Web Service method I got the error:
java.lang.RuntimeError Mismatched types
Yes, I have changed the input parameter for the method to Vector and made sure that I've imported the same types of Vectors.
This is my Web Service and my app, so, I do have full range of it. I am willing to change any portion of both the app and the WS. If you have any ideas please let me know. This is how I am creating my request for the Web Service:
This is a full method that I am trying to use the Vector in.
public ArrayList<Contacts> getLocationslist(Vector<Integer> list){
ArrayList<Contacts> contacts = new ArrayList<Contacts>();
String SOAP_ACTION = "urn:getLocationsList";
String METHOD_NAME = "getLocationsList";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("arg0", list);
SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
int i = 0;
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
while (i < resultsRequestSOAP.getPropertyCount()){
Contacts cont = new Contacts();
try {
Ksoap2ResultParser.parseBusinessObject(resultsRequestSOAP.getProperty(i).toString(), cont);
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
contacts.add(cont);
i = i + 1;
}
} catch (Exception e) {
e.printStackTrace();
}
return contacts;
}
I am counting on you SO!! Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过几次尝试后,我只是选择使用字符串分词器。
只需创建一个字符串,其中包含您希望在数组中发送的所有值。我创建了数组,然后使用
然后让分词器按每个“,”分割值。
效果很好。我现在假设 Ksoap2 无法序列化任何数组类型。谢谢你们!
-尼恩
After a few more attempts, I just went with using a String Tokenizer.
Just Create a String that contains all of the Values that you wish to send in an Array. I created the Array, then used
Then let the tokenizer split the values by each ",".
Which worked well. I'm just going to assume at this point that Ksoap2 cannot Serialize any array type. Thanks Guys!
-Ninn