• Latest Code...

    Featured Post

    Implementing Hilt in a Kotlin Android Jetpack Compose Project with MVVM Architecture

     In modern Android development, maintaining a scalable codebase can be challenging, especially when it comes to dependency management. Hilt,...

    How to communicate WCF webservices in android applications

    - First you have to create wcf webserices, then you have defines some necessary thing to communicate with wcf.

    You have to recognize the following in your wsdl file:

    Method Name and Soap Action:


    Namespace:

    URL:

    Download ksoap 2 and import in libs folder in android:
               

    To download a file from there, right click on "View raw file" and select "Save Link as" (this label differs for different browsers) and you will get the full jar downloaded.

    The latest release artifact would be available at

    with a direct download url of

    Now you have to defines following java code in your android application:

    import org.ksoap2.SoapEnvelope;
    import org.ksoap2.serialization.SoapObject;
    import org.ksoap2.serialization.SoapPrimitive;
    import org.ksoap2.serialization.SoapSerializationEnvelope;
    import org.ksoap2.transport.AndroidHttpTransport;
    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.widget.TextView;

    public class Test extends Activity {

    public class SoapTask extends AsyncTask<Void, Void, Void> {
    private final ProgressDialog dialog = new ProgressDialog(Test.this);
    protected void onPreExecute() {

    this.dialog.setMessage("Checking in...");
    this.dialog.show();

    }

    @Override
    protected Void doInBackground(Void... arg0) {
    try{
    WebServiceCallExample();
    }catch (Exception e){
    e.printStackTrace();
    }
    return null;
    }

    protected void onPostExecute(Void result) {
    TextView tv = (TextView) findViewById(R.id.Result);
    tv.setText(test_string);
    if (this.dialog.isShowing()){
    this.dialog.dismiss();
    }
    }

    }

    private String test_string;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test);
    new SoapTask().execute();
    }

    @SuppressWarnings("deprecation")
    public void WebServiceCallExample() {
    final String NAMESPACE = "http://tempuri.org/";
    final String URL = "http://yoururl.com/testService.svc";
    final String METHOD_NAME = "SayHello";
    final String SOAP_ACTION = "http://tempuri.org/IWFPService/SayHello";

    SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);

    /* Set the web service envelope */
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(Request);
    System.out.println("Request::" + Request.toString());

    AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
    try{
    androidHttpTransport.call(SOAP_ACTION, envelope);
    //SoapObject response = (SoapObject) envelope.getResponse();
    SoapPrimitive sp = (SoapPrimitive) envelope.getResponse();

    SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
    System.out.println("Response::" + resultsRequestSOAP.toString());
    test_string = sp.toString();
    }catch (Exception e){
    e.printStackTrace();
    }
    }
    }


    test.xml layout file here:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="vertical" >


        <TextView
            android:id="@+id/Result"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="7dip"
            android:layout_marginRight="7dip"
            android:gravity="fill_vertical|fill_horizontal"
            android:layout_gravity="center_horizontal"
             android:textSize="24dip" android:text="test"
            android:textStyle="bold" >
        </TextView>

    </LinearLayout>


    You have got following output:



    If you have any Problem please go to these link, which is more helpful for you:
    http://stackoverflow.com/questions/tagged/android+ksoap2
    https://code.google.com/p/ksoap2-android/wiki/Links
    http://www.wsdl2code.com/pages/Example.aspx
    http://code.tutsplus.com/tutorials/consuming-web-services-with-ksoap--mobile-21242
    http://easywsdl.com/

    Contact Form

    Name

    Email *

    Message *