0

我在使用 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 的真正样子。我试图设置此调试但不知道如何设置。因此,我不知道如何检索所有这些...

4

1 回答 1

0

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

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

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

于 2013-01-14T07:37:51.020 回答