如何使用KSOAP在Java中序列化字符串数组中的xml对象?

如何使用KSOAP在Java中序列化字符串数组中的xml对象?,java,soap,ksoap2,Java,Soap,Ksoap2,我从服务器(WSDL SOAP)获得了以下代码的响应: HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.or

我从服务器(WSDL SOAP)获得了以下代码的响应:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetChanelResponse xmlns="http://tempuri.org/">
      <GetChanelResult>
        <string>string</string>
        <string>string</string>
      </GetChanelResult>
    </GetChanelResponse>
  </soap:Body>
</soap:Envelope>
此类用于数据存储

public class Main {

    public static String SOAP_ACTION="http://tempuri.org/GetChanel";
    public static String METHOD_NAME="GetChanel";
    public static String NAMESPACE="http://tempuri.org/";
    public static String URL="http://www.mcds.co.il/YouTube/ChanelApi.asmx";

    /**
     * @param args
     */
    public static void main(String[] args) {

        XMLRez documentIdVector=new XMLRez();


        PropertyInfo documentIdsPropertyInfo = new PropertyInfo();
        documentIdsPropertyInfo.setName("GetChanelResult");
        documentIdsPropertyInfo.setValue(documentIdVector);
        documentIdsPropertyInfo.setType(documentIdVector.getClass());

        // TODO Auto-generated method stub
        SoapObject request=new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty(documentIdsPropertyInfo);
        //request.addProperty("Celsius", "5");

        SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);

        envelope.dotNet=true;      
        envelope.setOutputSoapObject(request);
        envelope.addMapping(NAMESPACE, "GetChanelResult", new XMLRez().getClass());

        //AndroidHttpTransport aht=new AndroidHttpTransport(URL);
        HttpTransportSE aht =new HttpTransportSE(URL);

        try {
            aht.call(SOAP_ACTION, envelope);
            XMLRez prim=(XMLRez)envelope.bodyIn;
        } catch (Exception e) {
            //Log.e("exp", e.getMessage());
            System.out.println(e.getMessage());
        }
    }

}  

我使用这个类从服务获取数据。但我总是遇到异常“org.ksoap2.serialization.SoapObject不能强制转换为XMLRez”。哪里会出错?

使用getResponse而不是bodyIn。您将得到一个SoapObject,然后可以将其解析到pojo中

public class Main {

    public static String SOAP_ACTION="http://tempuri.org/GetChanel";
    public static String METHOD_NAME="GetChanel";
    public static String NAMESPACE="http://tempuri.org/";
    public static String URL="http://www.mcds.co.il/YouTube/ChanelApi.asmx";

    /**
     * @param args
     */
    public static void main(String[] args) {

        XMLRez documentIdVector=new XMLRez();


        PropertyInfo documentIdsPropertyInfo = new PropertyInfo();
        documentIdsPropertyInfo.setName("GetChanelResult");
        documentIdsPropertyInfo.setValue(documentIdVector);
        documentIdsPropertyInfo.setType(documentIdVector.getClass());

        // TODO Auto-generated method stub
        SoapObject request=new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty(documentIdsPropertyInfo);
        //request.addProperty("Celsius", "5");

        SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);

        envelope.dotNet=true;      
        envelope.setOutputSoapObject(request);
        envelope.addMapping(NAMESPACE, "GetChanelResult", new XMLRez().getClass());

        //AndroidHttpTransport aht=new AndroidHttpTransport(URL);
        HttpTransportSE aht =new HttpTransportSE(URL);

        try {
            aht.call(SOAP_ACTION, envelope);
            XMLRez prim=(XMLRez)envelope.bodyIn;
        } catch (Exception e) {
            //Log.e("exp", e.getMessage());
            System.out.println(e.getMessage());
        }
    }

}