1

I am trying to call java webservice form android application but unable to call it. When I generate WSDL file, SOAPAction showing blank

string(<soap:operation soapAction=""/>) in soap:operation.

My android application code:

public class MainActivity extends Activity {

private static final String SOAP_ACTION = "http://com/add";
private static final String METHOD_NAME = "add";
private static final String NAMESPACE = "http://com/";
private static final String URL = "http://localhost:8080/WebApplication1/demo";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

        Button button=(Button)findViewById(R.id.button1);
        button.setOnClickListener(new OnClickListener() {


        @Override
        public void onClick(View v) {
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

            PropertyInfo pi1 = new PropertyInfo();
            pi1.setName("i");
            pi1.setValue(3);
            pi1.setType(int.class);
            request.addProperty(pi1);

            PropertyInfo pi2 = new PropertyInfo();
            pi2.setName("j");
            pi2.setValue(3);
            pi2.setType(int.class);
            request.addProperty(pi2);

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

            // HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);


            try {
                ((TextView) findViewById(R.id.textView1)).setText(String
                        .valueOf("The WebService is about to call"));
                androidHttpTransport.call(SOAP_ACTION, envelope);
                ((TextView) findViewById(R.id.textView1)).setText(String
                        .valueOf("The WebService call is done"));

                SoapPrimitive response = (SoapPrimitive) envelope.getResponse();

                ((TextView) findViewById(R.id.textView1)).setText(String
                        .valueOf(response.toString()));

                ((TextView) findViewById(R.id.textView1)).setText(String
                        .valueOf("Done"));

            } catch (Exception e) {
                e.printStackTrace();
                Log.e("Err", "Error Says: " + e.toString());
            }

        }
    });
}

}

There is showing an exception network on main thread exception

2

1 Answer 1

4

Because you are calling the web service in your main thread.This must be done in the background using background thread.You can use asyntask for background operations.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.