如何使用soap库将String数组传递给Web服务?

时间:2013-05-15 04:37:06

标签: android web-services xml-serialization android-ksoap2 arrays

我需要将一个字符串数组传递给一个预定义的webserivce,用于接受一个字符串值数组。但是,当我创建一个soap信封并将 array.class string.class 属性设置为请求时,它会抛出序列化错误

对上述内容有何建议?应该建议的数据类型或方法可以解决相同的问题。

 SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);

    PropertyInfo p1 = new PropertyInfo();
    p1.setName("items");
    p1.setValue(results);
    p1.setType(String.class); // else Array.class.
    request.addProperty(p1);

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

        HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
        httpTransport.debug = true;
        httpTransport.call(SOAP_ACTION, envelope);
                       // throws an error in the above.

        result = httpTransport.responseDump;

2 个答案:

答案 0 :(得分:2)

这是KSOAP2 for Android库的一个已知问题,目前它只是不支持数组。问题描述为here

可以找到第三方补丁,解决方案和示例here

查看这些链接,您可以找到答案。

答案 1 :(得分:0)

只需在循环中传递参数名称和值:

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
for (int i=0; i<itemId.length; i++){
    request.addProperty("itemID",itemId[i]);
}
ht.call(SOAP_ACTION, envelope);

使用request.addProperty

在循环中传递parametername和item值