0

我需要在我的 android 应用程序中访问 .NET 网络服务。我是使用 ksoap2 库完成的。我设置了连接和一切,但我无法从服务中取回数据。该服务应该发回一组值。我如何捕捉这些价值观?

这是我访问 Web 服务的 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>
4

2 回答 2

2

检查这个。它是在 android 中访问 ksoap2 Web 服务的好教程。

于 2012-06-07T10:05:55.997 回答
0

您可以使用以下代码完成这项工作:

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
System.out.println(request);
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
HttpTransportSE httpTransportSE = new HttpTransportSE(URL);
httpTransportSE.debug = true;
try {
    httpTransportSE.call(SOAP_ACTION, envelope);

} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (XmlPullParserException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

String ss = httpTransportSE.requestDump;
Log.d("Result", ss);
System.out.println(ss);
于 2012-09-27T08:44:42.757 回答