0

I am getting Exception while using this code, but it works with other links.

public class WebserviceCall {

    static WebserviceCall com;
    String namespace = "http://tempuri.org/";
    private String url = "http://sicsglobal.co.in/T-Drive/WebService_TDrive.asmx";
    String SOAP_ACTION;
    SoapObject request = null, objMessages = null;
    SoapSerializationEnvelope envelope;
    AndroidHttpTransport androidHttpTransport;

    public static WebserviceCall getInstance() {
        if (com == null)
            return new WebserviceCall();
        else
            return com;
    }

    protected void SetEnvelope() {
        try {
            envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            androidHttpTransport = new AndroidHttpTransport(url);
            androidHttpTransport.debug = true;

        } catch (Exception e) {
            System.out.println("Soap Exception SetEnvelope (); \n"
                    + e.toString());
        }
    }

    public String getConvertedWeight(String MethodName, String thisUsername,
            String thisPassword) {
        try {
            SOAP_ACTION = namespace + MethodName;
            request = new SoapObject(namespace, MethodName);

            request.addProperty("userId", "" + thisUsername.trim());
            request.addProperty("password", thisPassword.trim());

            SetEnvelope();

            try {
                androidHttpTransport.call(SOAP_ACTION, envelope);
                String result = envelope.getResponse().toString();
                return result;
            } catch (Exception e) {
                return e.toString();
            }
        } catch (Exception e) {
            // TODO: handle exception
            return e.toString();
        }
    }

}
Denny Mathew
  • 842
  • 3
  • 13
  • 31

2 Answers2

1

You should prepare your soap request then you can do a proper http request because the webservice that you are connecting is a soap service, for this you can use ksoap2-android to prepare a soap request

also take a look at here How to call a SOAP web service on Android

Community
  • 1
  • 1
Ismail Sahin
  • 2,640
  • 5
  • 31
  • 58
0

Try to use Asynctask.

private class Task extends AsyncTask<String, Void, String> {

    protected void onPreExecute() {

    }

    @Override
    protected String doInBackground(String... urls) {

                    //your code here
            return response;
    }

    @Override
    protected void onPostExecute(String response) {
        //treat the response here   
    }
}

Look here for more information about it.

If this dosn't work, post your logcat.

Bruno Pinto
  • 2,013
  • 3
  • 23
  • 33