2014-04-20 267 views
2

我是Android新手。 我正在使用soap的webservice,我試圖匹配來自請求的數據,並希望得到迴應。我在android中實現了soap演示,但沒有通過標籤獲取數據。 我在這裏粘貼肥皂的方法。如何發送請求並從android中獲得響應soap

POST /InflAirBook.asmx HTTP/1.1 
Host: airwebservice.ezeeibe.com 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 
SOAPAction: "InFLAirBookService/InflAirGDSLCCAvail" 

<?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> 
    <InflAirGDSLCCAvail xmlns="InFLAirBookService"> 
     <AccountID>string</AccountID> 
     <AccountPassword>string</AccountPassword> 

    </InflAirGDSLCCAvail> 
    </soap:Body> 
</soap:Envelope> 

HTTP/1.1 200 OK Content-Type:text/xml;字符集= UTF-8 的Content-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> 
    <InflAirGDSLCCAvailResponse xmlns="InFLAirBookService"> 
     <InflAirGDSLCCAvailResult>string</InflAirGDSLCCAvailResult> 
    </InflAirGDSLCCAvailResponse> 
    </soap:Body> 
</soap:Envelope> 

我的問題是如何解析它的Android?

請幫助我如何發送請求並從中獲得響應。

在此先感謝

回答

0

我會建議爲KSOAP ..這是鏈接https://code.google.com/p/ksoap2-android/

+0

感謝響應,但是你能告訴我我如何訪問這段代碼的soap body,請提供一些方法,其實我已經實現了soap demo,但沒有通過標籤獲取數據。 – Ash

0

試試這個,我應該這將工作:

public void GetData() { 
    try{ 
    SoapObject request = new SoapObject("InFLAirBookService", 
    "InflAirGDSLCCAvail");// second parameter is your method name which you want to call 

    request.addProperty("AccountID", value1);//value1 contains value of AccountID 

    request.addProperty("AccountPassword", value2);//value2 contains value of AccountPassword 

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
      SoapEnvelope.VER11); 

    envelope.dotNet = true; 

    envelope.setOutputSoapObject(request); 

    HttpTransportSE androidHttpTransport = new 
    HttpTransportSE("airwebservice.ezeeibe.com/InflAirBook.asmx"); 


    androidHttpTransport.call("InFLAirBookService/InflAirGDSLCCAvail", 
envelope); 

    SoapPrimitive objs = (SoapPrimitive) 
envelope.getResponse();//objs will have the response from webservice in string 
//if SoapPrimitive does not work then write SoapObject. 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 
} 
相關問題