我正在为应用程序使用Web服务,以从外部服务器获取数据。我能够连接到服务器,发送我的SOAP请求,并能够将数据作为SoapObject返回到我的android类。
在这里,我无法解析此SoapObject来检索来自Web服务的值(作为字符串)。
我的代码在这里:

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list);
        mInflater =  (LayoutInflater)getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
       System.out.println("Entered "+getClass().getSimpleName());
       //Calling the web service to get the documents list
       callService("getDocumentsList","http://wservice.friedmaggy.com/getDocumentsList");


-我创建了callService方法来调用Web服务:

public void callService(String operation, String soapaction)
    {
        try {
            String SOAP_ACTION = soapaction;
            String OPERATION_NAME = operation;
            String WSDL_TARGET_NAMESPACE =   getString(R.string.targetNamespace);
            String SOAP_ADDRESS = getString(R.string.soapAddress);
            SoapObject request = new SoapObject(
                    WSDL_TARGET_NAMESPACE, OPERATION_NAME);
             System.out.println("SOAP_ACTION "+SOAP_ACTION);
             System.out.println("OPERATION_NAME "+OPERATION_NAME);
             System.out.println("WSDL_TARGET_NAMESPACE "+WSDL_TARGET_NAMESPACE);
             System.out.println("SOAP_ADDRESS "+SOAP_ADDRESS);
            // System.out.println("SOAP_ACTION "+SOAP_ACTION);

            PropertyInfo propInfo = new PropertyInfo();

             SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);

             HttpTransportSE httpTransport = new HttpTransportSE(
                    SOAP_ADDRESS);
envelope.setOutputSoapObject(request);

            httpTransport.call(SOAP_ACTION, envelope);

            SoapObject response = (SoapObject) envelope.bodyIn;


            if(response.getPropertyCount()>0){
                data=new StringBuilder();

            for (int i = 0; i < response.getPropertyCount(); i++) {

                Course c = new Course((SoapObject) response.getProperty(i));

                courseList.add(c);

            }

   for (Course c : courseList) {

                data.append("CourseName :" + c.getName());

                results.add(c.getName());
            }


-如上所示,我正在将整个响应对象传递给另一个bean类以获取值。

您能帮我如何解析此响应对象以获取所需的String值。

最佳答案

androidHttpTransport.call(SOAP_ACTION, envelope);
Object response = envelope.getResponse();

Vector<SoapObject> res= null;

if (response instanceof SoapObject) {
         res = new Vector();
     res.add((SoapObject) response);
     } else if (response instanceof Vector) {
             res = (Vector<SoapObject>) response;
         }

 for(SoapObject so1: res){
             //retrieve String here from soap object using this
                     so1.getProperty(0).toString();
    //then so1.getProperty(1).toString and likewise
         }

10-08 06:19