Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a .NET web service from android? [closed]

I need to call a web service with a URL something like: "http://192.168.1.19/TestWeb/WebService.asmx" from android.

Please anyone help me with a full example?

like image 225
Rajapandian Avatar asked Jun 26 '09 10:06

Rajapandian


People also ask

How to call service in Android?

A service is started when an application component, such as an activity, starts it by calling startService(). Once started, a service can run in the background indefinitely, even if the component that started it is destroyed. A service is bound when an application component binds to it by calling bindService().

Is .NET compatible with Android?

. NET is a developer platform made up of tools, programming languages, and libraries for building many different types of applications. Xamarin extends the . NET developer platform with tools and libraries specifically for building apps for Android, iOS, tvOS, watchOS, macOS, and Windows.

How do I access web services in Android Studio?

Launch Android Studio and click the New Project icon to create a new Android project. In the New Project dialog, enter information for the new project, as shown in Figure 1. In the Application Name box, enter the name of the Android project, AccessWebServiceApp.

On which thread service work in Android?

Service runs in the main thread of its hosting process; the service does not create its own thread and does not run in a separate process unless you specify otherwise.


1 Answers

Finally, I got the solution for my own question.

Here is the code:

package projects.ksoap2sample;



import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.*;
import android.os.*;
import android.widget.TextView;

public class ksoap2sample extends Activity {
    /** Called when the activity is first created. */
    private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld";

    private static final String METHOD_NAME = "HelloWorld";

    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String URL = "http://192.168.1.19/TestWeb/WebService.asmx";
    TextView tv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv=(TextView)findViewById(R.id.text1);
        call();

    }

    public void call()
    {
        try {

            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

            request.addProperty("passonString", "Rajapandian");

            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());
            }
    }
}
like image 196
Rajapandian Avatar answered Oct 02 '22 05:10

Rajapandian