title: Webservice SOAP in Android
body: <p>I'm starting to use webservices in Android and I followed this tutorial: <a href="http://blog.sencide.com/2011/06/create-web-service-using-apache-axis2.html" rel="nofollow">Create Web Service in Java Using Apache Axis2 and Eclipse</a> to create and consume the webservice. This tutorial explain the client side application in Java but with some others tutorials I was able to consume the WS in Android like this: </p>
  
  <pre><code>package com.android.webservices;
  
  import org.ksoap2.SoapEnvelope;
  import org.ksoap2.serialization.SoapObject;
  import org.ksoap2.serialization.SoapSerializationEnvelope;
  import org.ksoap2.transport.HttpTransportSE;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  
  public class AddNumbersWSActivity extends Activity {
  /** Called when the activity is first created. */
  
  private String METHOD_NAME = "addTwoNumbers"; // our webservice method name
  private String NAMESPACE = "http://sencide.com"; // Here package name in webservice with reverse order.
  private String SOAP_ACTION = "http://sencide.com/addTwoNumbers"; // NAMESPACE + method name
  private static final String URL = "http://192.168.1.214:8080/axis2/services/FirstWebService?wsdl"; // you must use ipaddress here, don’t use Hostname or localhost
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      Button addButton = (Button) findViewById(R.id.button1);
  
      addButton.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
              // TODO Auto-generated method stub
              try
              {
                  SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                  EditText num1 = (EditText) findViewById(R.id.editText1);
                  EditText num2 = (EditText) findViewById(R.id.editText2);
                  request.addProperty("firstNumber", Integer.valueOf(num1.getText().toString()));
                  request.addProperty("secondNumber", Integer.valueOf(num2.getText().toString()));
                  SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  //                  envelope.dotNet = true;
                      envelope.setOutputSoapObject(request);
                      HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                      androidHttpTransport.call(SOAP_ACTION,envelope);
                      Object result = envelope.getResponse();
                      System.out.println("Result : " + result.toString());
                      ((TextView) findViewById (R.id.textView4)).setText(result.toString());
                  } catch (Exception E) {
                      E.printStackTrace();
                  }
              }
          });
  
      }
  }
  </code></pre>
  
  <p>But now I have some questions about consuming WS in Android:</p>
  
  <ol>
  <li>As I can see <a href="https://code.google.com/p/ksoap2-android/downloads/list?can=1&amp;q=&amp;colspec=Filename%20Summary%20Uploaded%20ReleaseDate%20Size%20DownloadCount" rel="nofollow">here</a>, the kSOAP2 library is deprecated... Should I continue to use this library or I need another tool? If yes, which one?</li>
  <li>Is it possible to know the <code>NAMESPACE</code>, <code>METHOD_NAME</code>, <code>SOAP_ACTION</code> using only the WSDL of the service?</li>
  <li>Can I generate some code automatically using WSDL (like WSDL2Java tool that is used for Java applications)?</li>
  <li>At the <code>addProperty(String name, Object value)</code> method, can I used arbitrary <code>name</code> or it should follow a rule?</li>
  </ol>
  
  <p>Thanks in advance!</p>