簡體   English   中英

如何在Android中發送請求並獲得Soap的響應

[英]How to send request and get response from soap in android

我是Android新手。 我正在使用肥皂進行網絡服務,我正在嘗試匹配請求中的數據並希望獲得響應。 我已經在android中實現了肥皂演示,但沒有通過標簽獲取數據。 我在這里粘貼肥皂方法。

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內容類型:text / xml; charset = utf-8內容長度:長度

<?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解析它?

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

提前致謝

我會建議使用Ksoap。這是鏈接https://code.google.com/p/ksoap2-android/

試試這個,我應該這樣做:

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();
    }
}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM