welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Wednesday, June 27, 2012

Tutorial to Connect dotnet web service in android application

It’s very interesting to a talk about web service, here I will explain to connect simple type dot net web service using android application. By using a web service we can easily get the desired data by sending request.
Before I start the topic we discuss, what are the files needed to start to access the web service.
Steps to follow:
1.       Make sure you have added the Ksopa2 jar file on your directory, if you need help to add the file refer the below link, download and follow the steps to add ksoap2 jar file.

2.       Add the below code on androidManifest.xml file, below code permit the application to connect on intenet. Add the code outside the application tag in androidManifest.xml file

<uses-permission android:name="android.permission.INTERNET"/>

In a dotnet web service we must know about these things i.e.

1. Methods name-Here I call the methods name as MobileLogin
2. Namespace-Here I call namespace name as
4. Passing parameter name-here I used usrname and password

So you before workout your project collect all the details about web service.

Use the below code
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.os.Bundle;
public class webActivity extends Activity {
                /** Called when the activity is first created. */
                HttpTransportSE androidHttpTransport;
                String NAMESPACE = "";
                String METHOD_NAME = "MobileLogin";
                String SOAP_ACTION = "";
                String URL = "";
                public void onCreate(Bundle savedInstanceState) {

                                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(

                                request.addProperty("usrname ", "");
                                request.addProperty("password ", "abcdefg");
                                envelope.implicitTypes = true;
                                envelope.dotNet = true;
                                int Timeout1 = 20000;
                                androidHttpTransport = new HttpTransportSE(URL, Timeout1);
                                androidHttpTransport.debug = true;
                                try {
                                      , envelope);
                                                Object response = envelope.getResponse();
                                                String rslt;
                                                //Finally you get the result from web service
                                } catch (Exception e) {
                                                // TODO: handle exception

That’s it above code works perfectly …Incase if you need the source code put your commnets with your email id…I will forward the source code.
Happy coding…keep reading


Post a Comment