Search code examples
androidweb-servicessoapksoap2

Android: connect myApp with a webService


i'm working on it from 2 days, already searched for tutorials and other questions here but i failed to do it. The problem is: the code seems valid, I compared it with everybody else but i fail to reach the "Correct answer" from my webservice. This is the code for the 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) {
    }
}

I receive an answer but is not correct, infact I receive:

Received code:

without the code that i passed on "Request" object. The correct response that I'm expect, tested with SoapUI, is

Received code: "scan result"

that's a String.

This is the xml of the webService:

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>

Solution

  • Resolved: Need to put an "/" on my web service, the CODE wrote here is good.