[将数组 使用KSOAP2发送到Web服务

问题描述 投票:0回答:1

我在使用KSOAP2的Android项目中遇到问题。我想将新的标记检测发送到Web服务。我的Web服务中有一个称为AddNewDetection的方法。我把功能描述的图片。我有这个错误

 W/System.err:     at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:784)
 W/System.err:     at org.ksoap2.serialization.SoapSerializationEnvelope.writeProperty(SoapSerializationEnvelope.java:764)
 W/System.err:     at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:688)
 W/System.err:     at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBodyWithAttributes(SoapSerializationEnvelope.java:664)
 W/System.err:     at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:777)
W/System.err:     at org.ksoap2.serialization.SoapSerializationEnvelope.writeBody(SoapSerializationEnvelope.java:634)
 W/System.err:     at org.ksoap2.SoapEnvelope.write(SoapEnvelope.java:205)
W/System.err:     at org.ksoap2.transport.Transport.createRequestData(Transport.java:161)
W/System.err:     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:149)
 W/System.err:     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
W/System.err:     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)
 W/System.err:     at com.example.patrickrogerapp.common.QueryUtils.sendData(QueryUtils.kt:118)`

我必须将字符串数组传递给Web服务。而且我做不到。我正在使用Kotlin 1.3.50和KSOAP2 3.6.4]

我尝试过使用ArrayList之类的不同方法,...我没有找到解决问题的方法。

提前感谢您的帮助!

    fun AddNewDetection(detectionDateTime : DateTime, idAction : int, idBox: int?, idProduit : int?, idShop: int?, numberList: Array<String>): Void

fun sendData(action: Int, idBox:Int?, idProduct: Int, idShop: Int, tags: Array<String>): SoapSerializationEnvelope {
        SOAP_ACTION = "http://tempuri.org/IStelStockService/AddNewDetection"

        val envelope = SoapSerializationEnvelope(SoapEnvelope.VER11)
        val request = SoapObject(NAMESPACE, "AddNewDetection")
        envelope.implicitTypes = true

        val pi = PropertyInfo()
        pi.setName("dectectionDateTime")
        pi.type = MarshalDate::class.java
        pi.value = Date(System.currentTimeMillis())
        MarshalDate().register(envelope)
        request.addSoapObject(SoapObject().addProperty(pi))

        request.addProperty("idAction", action)
        request.addProperty("idBox", idBox)
        request.addProperty("idProduit", idProduct)
        request.addProperty("idShop", idShop)
        request.addProperty("numberList", tags)

        val item = PropertyInfo()
        item.setType(Array<String>::class.java)
        item.setName("numberList")
        item.value = tags
        request.addProperty(item)

        envelope.dotNet = true
        envelope.setOutputSoapObject(request)

        val httpTransport = HttpTransportSE(URL)
        try {
            // This is the actual part that will call the webservice by setting the desired
            // header SOAP Action header field.
            httpTransport.call(SOAP_ACTION, envelope)
            Log.d("PR_DEBUG", envelope.response.toString())
        } catch (e: IOException) {
            // Many kinds of exceptions can be caught here
            Log.e(LOG_TAG, e.toString())
            e.printStackTrace()
        } catch (e: XmlPullParserException) {
            e.printStackTrace()
        }
        return envelope

    }`
android kotlin ksoap2 android-ksoap2
1个回答
0
投票

我找到了解决方案。我需要创建一个扩展Vector并实现KvmSerializable的类。然后将名称空间设置为“ http://schemas.microsoft.com/2003/10/Serialization/Arrays”。

这是我的课程:

public class StringArraySerializer extends Vector<String> implements KvmSerializable {
//n1 stores item namespaces:
String n1 = "http://schemas.microsoft.com/2003/10/Serialization/Arrays";

@Override
public Object getProperty(int arg0) {
    return this.get(arg0);
}

@Override
public int getPropertyCount() {
    return this.size();
}

@Override
public void setProperty(int arg0, Object arg1) {
    this.add(arg1.toString());
}

@Override
public void getPropertyInfo(int i, Hashtable hashtable, PropertyInfo propertyInfo) {
    propertyInfo.setName("string");
    propertyInfo.setType(PropertyInfo.STRING_CLASS);
    propertyInfo.setNamespace(n1);
}

}

这是将字符串数组添加到属性信息的方法:

val list = StringArraySerializer()
    list.add("aaa")
    list.add("bb")
    val propertyInfo = PropertyInfo()
    propertyInfo.setName("numberList")
    propertyInfo.value = list
    propertyInfo.type = StringArraySerializer::class.java
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.