Android: 将 myApp 与 webService 连接

Android: connect myApp with a webService

我从 2 天开始就在努力,已经在这里搜索了教程和其他问题,但我没有做到。 问题是:代码似乎有效,我将它与其他人进行了比较,但我无法从我的网络服务中到达 "Correct answer"。这是 Activity:

的代码
public void connect() {

    String scanResult = result.getContents();
    String URL = "http://192.168.1.10/wsatena/GestioneDatiVisitatore.asmx";
    String NAMESPACE = "http://atenainfo.it/serviziweb/";
    String METHOD_NAME = "TestWebService";
    String SOAP_ACTION = NAMESPACE + METHOD_NAME;

    SoapObject request = null, objMessages = null;
    SoapSerializationEnvelope envelope;

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

    StrictMode.setThreadPolicy(policy);
    envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    //envelope.implicitTypes = true;

    request = new SoapObject(NAMESPACE, METHOD_NAME);
    PropertyInfo propertyInfo = new PropertyInfo();
    propertyInfo.setName("idProgrForm");
    propertyInfo.setValue(scanResult);
    propertyInfo.setType(String.class);
    request.addProperty(propertyInfo);

    envelope.implicitTypes = true;
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    envelope.setAddAdornments(false);

    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    try {
        androidHttpTransport.debug = true;
        androidHttpTransport.call(SOAP_ACTION, envelope);
        //Get the response
        Object response = envelope.getResponse();
        String result = response.toString();
    }
    catch (Exception e) {
    }
}

我收到了一个答案但不正确,事实上我收到了:

Received code:

没有我传递给 "Request" 对象的代码。 使用 SoapUI 测试后,我期望的正确响应是

Received code: "scan result"

这是一个字符串。

这是网络服务的xml:

TestWebService

Test

The test form is only available for requests from the local machine.
SOAP 1.1

The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.

POST /wsatena/GestioneDatiVisitatore.asmx HTTP/1.1
Host: 192.168.1.10
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://atenainfo.it/serviziweb/TestWebService"

<?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>
    <TestWebService xmlns="http://atenainfo.it/serviziweb">
      <idProgrForm>string</idProgrForm>
    </TestWebService>
  </soap:Body>
</soap:Envelope>
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>
    <TestWebServiceResponse xmlns="http://atenainfo.it/serviziweb">
      <TestWebServiceResult>string</TestWebServiceResult>
    </TestWebServiceResponse>
  </soap:Body>
</soap:Envelope>
SOAP 1.2

The following is a sample SOAP 1.2 request and response. The placeholders shown need to be replaced with actual values.

POST /wsatena/GestioneDatiVisitatore.asmx HTTP/1.1
Host: 192.168.1.10
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <TestWebService xmlns="http://atenainfo.it/serviziweb">
      <idProgrForm>string</idProgrForm>
    </TestWebService>
  </soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <TestWebServiceResponse xmlns="http://atenainfo.it/serviziweb">
      <TestWebServiceResult>string</TestWebServiceResult>
    </TestWebServiceResponse>
  </soap12:Body>
</soap12:Envelope>

已解决: 需要在我的web服务上加一个“/”,这里写的CODE很好。