0
我需要在我的android應用程序中訪問.NET webservice。我用ksoap2庫做了它。我建立了連接和一切,但我無法從服務中獲取數據。該服務應該發回一組值。我如何捕獲這些價值?使用ksoap2從Web服務獲取多個值Android
這是我的java代碼來訪問網絡服務。
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
//code to get back the values here. This is my doubt.
//What code do I write here to get the values from the service ?
} catch (Exception e) {
e.printStackTrace();
}
這是從服務響應的格式。
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>
<GetControlResponse xmlns="http://tempuri.org/">
<GetControlResult>
<Id>int</Id>
<Belt>boolean</Belt>
<Lighting>boolean</Lighting>
<AutoSpeed>boolean</AutoSpeed>
<ManualSpeed>short</ManualSpeed>
<Projector>boolean</Projector>
<ProjecterPattern>short</ProjecterPattern>
</GetControlResult>
</GetControlResponse>
</soap:Body>
</soap:Envelope>
本教程使用僅返回一個值的服務。我需要從我的服務中獲得多個值。我不能做response.toString(),因爲我的迴應將包含各種值。 – Swayam