如何从对象获取值来自服务器,同时进行soap解析

时间:2013-09-20 05:22:35

标签: android ksoap2

我在使用Ksoap解析器进行soap解析时从服务器获得响应。现在我想从对象属性中获取值。

SoapObject obj = (SoapObject)envp.getResponse(); 
System.out.println("resultsString"+obj);

现在如果我想获得 RID alertsSummary 我将如何获得

resultsStringanyType{RID=201309201377618; alertDetailPopulated=true; alertsId=0; 
alertsSummary=anyType{}; destExpArrival=06:31; destSchArrival=06:30;
destinationStation=anyType{crsCode=BKJ; stationName=Beckenham Junction; }; 
expArrival=06:19; expDepart=06:20; otherAlertPresent=false; platformNo=3;
routeDetailPopulated=false; routeDetails=null; rsID=null; schArrival=06:19; 
schDepart=06:19; serviceAlertPresent=false; toc=SE; tocName=Southeastern; trainID=2M06; trainLastReportedAt=null; }

2 个答案:

答案 0 :(得分:0)

public void retrieveREsponsefromSoap(){   
  String METHOD_NAME = "GetAlldata";
  String SOAP_ACTION = "http://tempuri.org/1234.._Services/";
  SOAP_ACTION = SOAP_ACTION + METHOD_NAME;
  SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
  String SoapResult = null;

   SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envelope.setOutputSoapObject(request);

            envelope.dotNet = true;

            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            // this is the actual part that will call the webservice
            androidHttpTransport.call(SOAP_ACTION, envelope);

            // Get the SoapResult from the envelope body.
            if (envelope.bodyIn instanceof SoapFault) {
                SoapResult = ((SoapFault) envelope.bodyIn).faultstring;
            } else {
                SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
                SoapResult = resultsRequestSOAP.getProperty(0).toString();
            }

            Log.i(WebCalls, "Response " + SoapResult);
}

答案 1 :(得分:0)

// Get the SoapResult from the envelope body.
        if (envelope.bodyIn instanceof SoapFault) {
            SoapResult = ((SoapFault) envelope.bodyIn).faultstring;
        } else {
            SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
            SoapResult = resultsRequestSOAP.getProperty(0).toString();
        }

我希望这对你有用..