Calling web service from seems to hang

Posted by anothershrubery on Stack Overflow See other posts from Stack Overflow or by anothershrubery
Published on 2012-12-10T16:58:05Z Indexed on 2012/12/10 17:03 UTC
Read the original article Hit count: 228

Filed under:
|
|
|
|

I am trying to call an asmx web service from an Android app. Just literally started some Android development today. I've been following various solutions I have found on the net and on here and it seems it is more difficult than anticipated. I have tried various solutions and using KSoap2 seems to be the easiest way to implement this, well it would be if I could get it working.

I have the following code which works up until a point:

private class CallWebService extends AsyncTask<Void, Void, Void> {

    private static final String SOAP_ACTION = "http://tempuri.org/GetUser";
    private static final String METHOD_NAME = "GetUser";
    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String URL = "http://160.10.1.79:59315/Service1.asmx";
    TextView tv;

    @Override
    protected Void doInBackground(Void... params) {
        tv=(TextView)findViewById(R.id.txtMessage);

        try {
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet=true;
            envelope.setOutputSoapObject(request);

            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            androidHttpTransport.call(SOAP_ACTION, envelope);

            Object result = (Object)envelope.getResponse();

            tv.setText(result.toString());
        }
        catch (Exception e) {
            tv.setText(e.getMessage());
        }
        return null;
    }
}

It seems to hang at the line androidHttpTransport.call(SOAP_ACTION, envelope); Any ideas why? Is this the correct approach? Should I be looking in another direction?

© Stack Overflow or respective owner

Related posts about java

Related posts about android