簡體   English   中英

Android中的Ksoap2無法序列化

[英]Ksoap2 in android cannot serialize

我在Android中使用kso​​ap2

發送數字列表作為字符串

但是它有錯誤:

java.lang.runtimeexception無法序列化

我搜索此錯誤的解決方案,但結果未更改

能幫我嗎

public String Send(ArrayList<String> contactlist)
{
    try{
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo pi=new PropertyInfo();
            pi.setType(String.class);
            pi.setName("contactlist");
            pi.setValue(contactlist);
            request.addProperty("contactlist", pi);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy); 

        // Creating SOAP envelope           
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        new MarshalBase64().register(envelope); // this line is for serialization

        //You can comment that line if your web service is not .NET one.
        envelope.dotNet = true;

        envelope.setOutputSoapObject(request);
        AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport("http://10.0.2.2:54869/Service1.asmx");
        androidHttpTransport.debug = true;
}
    catch (Exception exception)
        {
            return exception.toString();
        }
    try
        {
            androidHttpTransport.call(SOAP_ACTION, envelope);
            //String result = envelope.getResponse().toString();
            return "";//result;
        }
    catch (Exception exception)
        {
            return exception.toString();
        }

使用此類進行序列化

public class MarshalDouble implements Marshal {
        public Object readInstance(XmlPullParser parser, String namespace,
                String name, PropertyInfo expected) throws IOException,
                XmlPullParserException {

            return Double.parseDouble(parser.nextText());
        }

        public void register(SoapSerializationEnvelope cm) {
            cm.addMapping(cm.xsd, "double", Double.class, this);

        }

        public void writeInstance(XmlSerializer writer, Object obj)
                throws IOException {
            writer.text(obj.toString());
        }
    }

將此行添加到信封中

    envelope.dotNet = true;
    envelope.implicitTypes = true;
    envelope.encodingStyle = SoapSerializationEnvelope.XSD;
    MarshalDouble md = new MarshalDouble();
    md.register(envelope);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM