使用KSOAP2接收整数数组

时间:2013-01-13 22:12:05

标签: android jax-ws ksoap2

我在使用KSOAP2接收整数数组时遇到问题。我按照http://code.google.com/p/ksoap2-android/wiki/CodingTipsAndTricks上的教程创建了以下类:

package pl.webcentral.reversi;

import java.util.Hashtable;
import java.util.Vector;

import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;

public class Fields extends Vector<String> implements KvmSerializable {

        /**
         * 
         */
        private static final long serialVersionUID = -1166006770093411055L;

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

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

        @Override
        public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
                arg2.name = "string";
                arg2.type = PropertyInfo.STRING_CLASS;
        }

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

}

发送数组:

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 

        PropertyInfo propInfo=new PropertyInfo();
        propInfo.setName("arg0");
        propInfo.setType(PropertyInfo.STRING_CLASS);
        propInfo.setValue(sessionId);

        request.addProperty(propInfo);

        // Sending the array representing our board:

        Fields fieldsVector = new Fields();

        for (int i=0; i<65; i++) {

            fieldsVector.add(move[i].toString());

        }

        PropertyInfo fieldsPropertyInfo = new PropertyInfo();
        fieldsPropertyInfo.setName("fields");
        fieldsPropertyInfo.setValue(fieldsVector);
        fieldsPropertyInfo.setType(fieldsVector.getClass());

        request.addProperty(fieldsPropertyInfo);

        PropertyInfo sessionPropertyInfo = new PropertyInfo();
        sessionPropertyInfo.setName("arg0");
        sessionPropertyInfo.setType(PropertyInfo.STRING_CLASS);
        sessionPropertyInfo.setValue(sessionId);
        request.addProperty(sessionPropertyInfo);

        envelope.setOutputSoapObject(request);

        envelope.addMapping(NAMESPACE, "fields", new Fields().getClass());

        HttpTransportSE androidHttpTransport = new HttpTransportSE(WSDL_URL);
        // androidHttpTransport.debug = true;


        try {
            androidHttpTransport.call(SOAP_ACTION, envelope);
        } catch (Exception e) {
            throw new RuntimeException("Unexpected exception", e);
        }

        try {
            SoapPrimitive resultsRequestSOAP = (SoapPrimitive) envelope.getResponse();
        } catch (SoapFault e) {
            System.out.println("Error adding move: " + e.faultstring);//można to ładnie jakoś pokazać na ekranie
            throw e;
        }
    }

现在我不知道XML的真实含义。我试着设置这个调试,但不知道如何。因此,我不知道如何检索所有这些......

1 个答案:

答案 0 :(得分:0)

对于转储请求和响应xml,请尝试:

androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
Log.d("dump Request: " ,androidHttpTransport.requestDump);
Log.d("dump response: " ,androidHttpTransport.responseDump);

如果您不知道您的网络服务是什么样的,SOAP UI对您来说是一个很好的工具。