Showing posts with label Android SOAP webservices. Show all posts
Showing posts with label Android SOAP webservices. Show all posts

Wednesday, December 11, 2013

ANDROID SOAP BASED WEB SERVICES TUTORIAL

ANDROID SOAP BASED WEB SERVICES TUTORIAL

A web service is any piece of software that makes itself available over the internet that can be remotely invoked using HTTP, that is, it can be activated using HTTP requests. XML is used to encode all communications to a web service. Web services allows you to expose the functionality of your existing code over the network but code are completely invisible to Web site surfers and software users. Their job is to run silently in the background,For example, a client invokes a web service by sending an XML message, then waits for a corresponding XML response. Because all communication is in XML, web services are not tied to any one operating system or programming language--Java can talk with Perl; Windows applications can talk with Unix applications,thus  providing a way for applications to work with each other to get the user the information or functionality he needs.
                Along with XML, Web Services uses standardized industry standard protocol for the communication. All the four layers (Service Transport, XML Messaging, Service Description and Service Discovery layers) uses the well defined protocol in the Web Services protocol stack. This standardization of protocol stack gives the business many advantages like wide range of choices, reduction in the cost due to competition and increase in the quality.
 Web Service Roles
There are three major roles within the web service architecture:
    Service provider:
    This is the provider of the web service. The service provider implements the service and makes it available on the Internet.
      Service requestor
      This is any consumer of the web service. The requestor utilizes an existing web service by opening a network connection and sending an XML request.
        Service registry
        This is a logically centralized directory of services. The registry provides a central place where developers can publish new services or find existing ones. It therefore serves as a centralized clearinghouse for companies and their services.

        Web Service Protocol Stack

        A second option for viewing the web service architecture is to examine the emerging web service protocol stack. The stack is still evolving, but currently has four main layers.
        Service transport
        This layer is responsible for transporting messages between applications. Currently, this layer includes hypertext transfer protocol (HTTP), Simple Mail Transfer Protocol (SMTP), file transfer protocol (FTP), and newer protocols, such as Blocks Extensible Exchange Protocol (BEEP).
        XML messaging
        This layer is responsible for encoding messages in a common XML format so that messages can be understood at either end. Currently, this layer includes XML-RPC and SOAP (Simple Object Access Protocol): SOAP is responsible for encoding XML messages so that they can be received and understood by any operating system over any type of network protocol.
        Service description
        This layer is responsible for describing the public interface to a specific web service. Currently, service description is handled via the Web Service Description Language (WSDL). (Web Services Description Language): WDSL is the SOAP of the UDDI (enough acronyms for you?). Basically, WDSL is the XML-based language that businesses use to describe their services in the UDDI. (Universal Description, Discovery and Integration): Described as a "yellow pages for the Internet," UDDI is an XML-based directory that allows businesses to list themselves, find each other and collaborate using Web services.
        Service discovery
        This layer is responsible for centralizing services into a common registry, and providing easy publish/find functionality. Currently, service discovery is handled via Universal Description, Discovery, and Integration (UDDI).
        Currently RESTfull webservices are more popular than SOAP based webservices,but still there are many 
        webservices that still work SOAP based.
        The Following project is a demonstration project for currency conversion between four different curriencies.it uses SOAP based  web services.We need ksoap2 lib for implementing this project.This project also demonstrates custom styling.
        1.Create  Android project with details as listed in the table below.
        Property name
        Property value
        Project name
        SRM_SOAPWebServices
        Package name
        in.ac.srmuniv.soapwebservice
        Activity name
        SRM_SOAPActivity
        Layout xml name
        main

        2.Download ksoap2-j2se-full-2.6.5 from ksoap offical website .Right click on project and then click on “Build path” then “Configure Build Path”.From Libraries Tab choose “Add Extarnal JARs” then choose your ksoap2-jse-full-2.6.5 jar file from downloads and click OK.

        Figure 1 Shows importing ksoap external library jar.
        3.Copy the code  to the file main.xml in res/layout folder 
        <?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:orientation="vertical" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:gravity="center_horizontal"
                android:text="@string/app_name"
                android:textSize="@dimen/headsize" />

            <TableLayout
                android:id="@+id/TableLayout1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="50dp" >

                <TableRow
                    android:id="@+id/tableRow1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="10dp"
                    android:layout_marginLeft="10dp" >

                    <Spinner
                        android:id="@+id/spinner1"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:drawSelectorOnTop="true"
                        android:prompt="@string/select_Category"/>
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="10dp"
                    android:layout_marginLeft="10dp">

                    <TextView
                        android:id="@+id/textView1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center_horizontal"
                        android:text="@string/to"
                        android:textAppearance="?android:attr/textAppearanceMedium"/>
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="10dp"
                    android:layout_marginLeft="10dp"
                    android:gravity="center_horizontal" >

                    <Spinner
                        android:id="@+id/spinner2"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow6"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="10dp"
                    android:layout_marginLeft="10dp" >

                    <Space android:layout_height="20dp"/>
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="10dp"
                    android:layout_marginLeft="10dp" >

                    <TextView
                        android:id="@+id/textView3"
                        style="@style/CodeFont"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="Enter Value of money to be converted"/>
                </TableRow>
            </TableLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <EditText
                    android:id="@+id/editText1"
                    android:layout_width="150dp"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="40dp"
                    android:layout_marginLeft="10dp"
                    android:inputType="numberDecimal"
                    android:maxLength="4" />

                <Button
                    android:id="@+id/button1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/convert" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/textView2"
                    style="@style/CodeFont"
                    android:layout_gravity="center_horizontal"
                    android:gravity="center_horizontal"
                    android:text="Converted"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textSize="@dimen/out"/>
            </LinearLayout>


        </LinearLayout>
        4.Copy the code  to the file row.xml in res/layout folder 
        <?xml version="1.0"encoding="utf-8"?>
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="1dip" >

            <ImageView
                android:id="@+id/image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

            <TextView
                android:id="@+id/country"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dip"
                android:layout_toRightOf="@+id/image"
                android:padding="2dip"
                android:textColor="@drawable/red"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/currency"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/country"
                android:layout_marginLeft="5dip"
                android:layout_toRightOf="@+id/image"
                android:padding="2dip"
                android:textColor="@drawable/darkgrey" />


        </RelativeLayout>
        5.Copy the code in SRM_SOAPActivity.java. Activity.
        packagein.ac.srmuniv.soapwebservice;

        importin.ac.srmuniv.soapwebservice.R;
        importandroid.app.Activity;
        importandroid.app.ProgressDialog;
        importandroid.content.Context;
        importandroid.os.AsyncTask;
        import android.os.Bundle;
        importandroid.view.LayoutInflater;
        import android.view.View;
        importandroid.view.ViewGroup;
        importandroid.widget.AdapterView;
        importandroid.widget.AdapterView.OnItemSelectedListener;
        importandroid.widget.ArrayAdapter;
        importandroid.widget.Button;
        importandroid.widget.EditText;
        importandroid.widget.ImageView;
        importandroid.widget.Spinner;
        importandroid.widget.TextView;
        importandroid.widget.Toast;

        public class SRM_SOAPActivity extends Activity {
            String[] country = { "British", "European", "American", "Indian" };

            String[] currency = { "Pounds ", "Euro", "Dollor", "Rupee" };
            String[] currency_abr = { "GBP", "EUR", "USD", "INR" };
            String to_curr, from_curr;

            int arr_images[] = { R.drawable.pound, R.drawable.euro, R.drawable.dollor,
                    R.drawable.rupee };
            TextView converted;
            Spinner from_currency;
            Spinner to_currency;
            EditText input;

            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                to_curr = "INR";
                from_curr = "USD";
                setContentView(R.layout.main);
                converted = (TextView) findViewById(R.id.textView2);
                input = (EditText) findViewById(R.id.editText1);
                converted.setText("");

                from_currency = (Spinner) findViewById(R.id.spinner1);
                from_currency.setAdapter(newMyAdapter(SRM_SOAPActivity.this,
                        R.layout.row, country));
                from_currency.setSelection(2);
                to_currency = (Spinner) findViewById(R.id.spinner2);
                to_currency.setAdapter(newMyAdapter(SRM_SOAPActivity.this,
                        R.layout.row, country));
                to_currency.setSelection(3);
                from_currency.setOnItemSelectedListener(newOnItemSelectedListener() {

                    public voidonItemSelected(AdapterView<?> parentView, View v,
                            int position, long id) {
                        Toast.makeText(getApplicationContext(),
                                "" + currency_abr[position], Toast.LENGTH_LONG).show();
                        converted.setHint(currency[position]);
                        from_curr = currency_abr[position];

                    }

                    public voidonNothingSelected(AdapterView<?> parentView) {
                        // your code here
                    }

                });
                to_currency.setOnItemSelectedListener(newOnItemSelectedListener() {

                    public voidonItemSelected(AdapterView<?> parentView, View v,
                            int position, long id) {
                        Toast.makeText(getApplicationContext(),
                                "" + currency_abr[position], Toast.LENGTH_LONG).show();
                        converted.setHint(currency[position]);
                        to_curr = currency_abr[position];

                    }

                    public voidonNothingSelected(AdapterView<?> parentView) {
                        // your code here
                    }

                });

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

                    @Override
                    public void onClick(View v) {

                        newDownloadData().execute(to_curr, from_curr, input.getText()
                                .toString());
                    }
                });

                converted = (TextView) findViewById(R.id.textView2);
            }

            class DownloadData extends AsyncTask<String, String, String> {

                ProgressDialog pd = null;

                @Override
                protected void onPreExecute() {
                    super.onPreExecute();
                    pd = newProgressDialog(SRM_SOAPActivity.this);
                    pd.setTitle("Converting...");
                    pd.setMessage("Please wait...");
                    pd.setCancelable(false);
                    pd.show();

                }

                @Override
                protected String doInBackground(String... params) {

                    String theResult = "";
                    String to_curr = params[0];
                    String from_curr = params[1];
                    String value = params[2];

                    try {
                        theResult = newSOAPclass().remotereq(to_curr, from_curr, value);

                    }

                    catch (Exception e) {
                        e.printStackTrace();
                    }

                    return theResult;
                }

                @Override
                protected void onPostExecute(String theResult) {
                    super.onPostExecute(theResult);
                    pd.dismiss();
                    double x;
                    try {
                        x = Double.parseDouble(theResult);
                    } catch(NumberFormatException e) {
                        // TODO Auto-generated catch block
                        x = 1;
                        input.setText("");
                    }
                    converted.setText(new Double(x).toString());
                }
            }

            public class MyAdapter extendsArrayAdapter<String> {

                public MyAdapter(Context context, int textViewResourceId,
                        String[] objects) {
                    super(context, textViewResourceId, objects);
                }

                @Override
                public View getDropDownView(int position, View convertView,
                        ViewGroup parent) {
                    return getCustomView(position, convertView, parent);
                }

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    returngetCustomView(position, convertView, parent);
                }

                public View getCustomView(int position, View convertView,
                        ViewGroup parent) {

                    LayoutInflater inflater = getLayoutInflater();
                    View row = inflater.inflate(R.layout.row, parent, false);
                    TextView label = (TextView) row.findViewById(R.id.country);
                    label.setText(country[position]);

                    TextView sub = (TextView) row.findViewById(R.id.currency);
                    sub.setText(currency[position]);

                    ImageView icon = (ImageView) row.findViewById(R.id.image);
                    icon.setImageResource(arr_images[position]);

                    return row;
                }
            }
        }

        6.Copy the code in SOAPclass.java.webservice java  class.
        package in.ac.srmuniv.soapwebservice;

        importorg.ksoap2.SoapEnvelope;
        importorg.ksoap2.serialization.PropertyInfo;
        importorg.ksoap2.serialization.SoapObject;
        importorg.ksoap2.serialization.SoapPrimitive;
        importorg.ksoap2.serialization.SoapSerializationEnvelope;
        import org.ksoap2.transport.HttpTransportSE;

        importandroid.os.StrictMode;
        import android.util.Log;

        public class SOAPclass {
            private final String NAMESPACE = "http://www.webserviceX.NET/";
            private final String URL = "http://www.webservicex.net/CurrencyConvertor.asmx";
            private final String SOAP_ACTION = "http://www.webserviceX.NET/ConversionRate";
            private final String METHOD_NAME = "ConversionRate";

            public SOAPclass() {
            }

            public String remotereq(String to_curr, String from_curr, String value) {

                // Strict mode is defined because executing network operations in the
                // main
                // thread will give exception
                // Strict mode is available only above version 9
                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                        .permitAll().build();
                StrictMode.setThreadPolicy(policy);

                // Create the soap request object
                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

                // Convert from
                String fromUnit = from_curr;
                // Convert to
                String toUnit = to_curr;
                if (value == null) {
                    value = "1";
                }

                // Set the property info for the to currency
                PropertyInfo FromCurrency = new PropertyInfo();
                FromCurrency.setName("FromCurrency");
                FromCurrency.setValue(fromUnit);
                FromCurrency.setType(String.class);
                request.addProperty(FromCurrency);

                PropertyInfo ToCurrency = new PropertyInfo();
                ToCurrency.setName("ToCurrency");
                ToCurrency.setValue(toUnit);
                ToCurrency.setType(String.class);
                request.addProperty(ToCurrency);

                // Create the envelop.Envelop will be used to send the request
                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                        SoapEnvelope.VER11);
                envelope.setOutputSoapObject(request);
                // Says that the soap webservice is a .Net service
                envelope.dotNet = true;

                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                String s = "";
                Double x = 1.0;
                try {
                    androidHttpTransport.call(SOAP_ACTION, envelope);

                    SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
                    // TextView v=(TextView) findViewById(R.id.currency);
                    // v.setText("1" +fromUnit +"=" +response.toString()+toUnit);

                    // Output to the log
                    s = response.toString();
                    x = Double.parseDouble(s) * Double.parseDouble(value);
                    Log.d("Converter", response.toString());

                } catch (Exception e) {
                    e.printStackTrace();
                }
                return x.toString();

            }

        }
        7.Modify the string.xml in res/values folder
        <?xml version="1.0"
        encoding="utf-8"?>
        <resources>
            <string name="app_name">SRM_CurrencyConvertorSOAP</string>
            <string name="action_settings">Settings</string>
            <string name="menu_settings">Menu</string>
            <string name="hello_world">Hello world!</string>

            <drawable name="white">#ffffff</drawable>
            <drawable name="black">#000000</drawable>
            <drawable name="green">#347C2C</drawable>
            <drawable name="pink">#FF00FF</drawable>
            <drawable name="violet">#a020f0</drawable>
            <drawable name="grey">#778899</drawable>
            <drawable name="red">#C11B17</drawable>
            <drawable name="yellow">#FFFF8C</drawable>
            <drawable name="PowderBlue">#b0e0e6</drawable>
            <drawable name="brown">#2F1700</drawable>
            <drawable name="Hotpink">#7D2252</drawable>

            <string name="select_Category">Select Category</string>

            <drawable name="darkgrey">#606060</drawable>
            <string name="to">to</string>
            <string name="convert">Convert</string>
            <color name="bk">#F0E0D0</color>
        </resources>
        8.Copy the code  to the file dimens.xml in res/valuesfolder 
        <resources>

            <!-- Default screen margins, per the Android Design guidelines. -->
            <dimen name="activity_horizontal_margin">16dp</dimen>
            <dimen name="activity_vertical_margin">16dp</dimen>
            <dimen name="convert">20sp</dimen>
            <dimen name="out">70sp</dimen>
            <dimen name="headsize">22sp</dimen>


        </resources>
        9.Modify the styles.xml in res/values folder 
        <?xml version="1.0"encoding="UTF-8"?>
        <resources xmlns:android="http://schemas.android.com/apk/res/android">
            <!--
                 Base application theme, dependent on API level. This theme is replaced
                by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
            -->
            <style name="AppBaseTheme"parent="android:Theme.Light">
                <!--
                     Theme customizations available in newer API levels can go in res/values-vXX/styles.xml,
                    while customizations related to backward-compatibility can go here.

                -->
            </style>

            <!-- Application theme. -->
            <style name="AppTheme"parent="AppBaseTheme">
                <!--
                     All customizations that are NOT specific to a particular API-level
                    can go here.

                -->
            </style>

            <style name="CustomTheme"parent="android:Theme">
                <item name="android:windowTitleSize">40dip</item>
                <item name="android:windowTitleBackgroundStyle">@style/AppTheme</item>
            </style>

            <style name="MyTheme"parent="android:Theme.Light">
                <item name="android:windowNoTitle">true</item>
                <item name="android:windowBackground">@color/bk</item>
                <item name="android:listViewStyle">@style/MySpinnerView</item>
            </style>

            <style name="MySpinnerView"parent="@android:style/Widget.Spinner">
                <item name="android:spinnersShown">@drawable/euro</item>
            </style>

            <style name="CodeFont"parent="@android:style/TextAppearance.Medium">
                <item name="android:layout_width">wrap_content</item>
                <item name="android:layout_height">fill_parent</item>
                <item name="android:textColor">#00BFA0</item>
                <item name="android:typeface">monospace</item>
            </style>


        </resources>


        10.Modify the Androidmanifest.xml 
        <?xml version="1.0"
        encoding="UTF-8"?>

        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="in.ac.srmuniv.soapwebservice"
            android:versionCode="1"
            android:versionName="1.0" >

            <uses-sdk
                android:minSdkVersion="15"
                android:targetSdkVersion="17" />

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

            <application
                android:icon="@drawable/ic_launcher"
                android:label="@string/app_name"
                android:theme="@style/AppTheme" >
                <activity
                    android:name=".SRM_SOAPActivity"
                    android:label="@string/app_name" >
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN"/>

                        <category android:name="android.intent.category.LAUNCHER"/>
                    </intent-filter>
                </activity>
            </application>

        </manifest>


        11.Run the Application in emulator/device

         

        Figure 2 shows currency conversion for different currencies .

        CODE EXPLANATION
        The SRM_SOAPWebservice application consists of MainActivity which has two customized spinners.User needs to select the 'From Currency' and 'To'Currency' to perform currency convertion.An array containing abbrevated currencies will be used to pass as parameter to the 'ConverterRate' webservice method based on the user selection in the spinners,also the value of currecy to be converted is taken from edittext.When button 'convert' is clicked it calls the SOAP_class which do execute the webservice call operation using ksoap2 lib.SOAP requests are synchronous and depending on network conditions it can take a while before even a simplest of requests can be invoked. This can cause application freezes and crashes. Therefore, it is highly recommended to do both the service invocation and request processing within a background thread in Android.This can be achieved using an AsyncTask, and putting the SOAP operation code inside its doInBackground method.
              This project also demonstrates the use of custom theme.Refer styles.xml
                                                                     In our example App we are going to use currency conversion functionality through web service http://www.webservicex.net/CurrencyConvertor.asmx


        Figure 3 Shows the screen shot of webservice page for currecncy converter
                               The following shows the piece of WSDL displaying webservice Namespace (http://www.webserviceX.NET/") ,operationname("ConversionRate"),parameters(FromCurrency","ToCurrency"),URL(<soap:address location="http://www.webservicex.net/CurrencyConvertor.asmx"/>) to send SOAP request


        <s:schema elementFormDefault="qualified" targetNamespace="http://www.webserviceX.NET/">
        <s:element name="ConversionRate">
        <s:complexType>
        <s:sequence>
        <s:element minOccurs="1" maxOccurs="1" name="FromCurrency" type="tns:Currency"/>
        <s:element minOccurs="1" maxOccurs="1" name="ToCurrency" type="tns:Currency"/>
        </s:sequence>
        </s:complexType>


        </s:element>
        .....
        .....
        <wsdl:service name="CurrencyConvertor">
        <wsdl:port name="CurrencyConvertorSoap" binding="tns:CurrencyConvertorSoap">
        <soap:address location="http://www.webservicex.net/CurrencyConvertor.asmx"/>
        </wsdl:port>
        <wsdl:port name="CurrencyConvertorSoap12" binding="tns:CurrencyConvertorSoap12">
        <soap12:address location="http://www.webservicex.net/CurrencyConvertor.asmx"/>
        </wsdl:port>
        <wsdl:port name="CurrencyConvertorHttpGet" binding="tns:CurrencyConvertorHttpGet">
        <http:address location="http://www.webservicex.net/CurrencyConvertor.asmx"/>
        </wsdl:port>
        <wsdl:port name="CurrencyConvertorHttpPost" binding="tns:CurrencyConvertorHttpPost">
        <http:address location="http://www.webservicex.net/CurrencyConvertor.asmx"/>
        </wsdl:port>


        </wsdl:service>

        Web service for java and android with kSOAP2  is implemented through the  following steps:
        1.First    Set the request information for the SOAP Envelope. The request information will be represented by a org.ksoap2.serialization.SoapObject object. 
        NAMESPACE = "http://www.webserviceX.NET/";
        METHOD_NAME = "ConversionRate";
                 SOAP_ACTION = "http://www.webserviceX.NET/ConversionRate"
        ....
        ....
           SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            2.Set parameters for method in webservice to be invoked
        // Set the property info for the to currency
                PropertyInfo FromCurrency = new PropertyInfo();
                FromCurrency.setName("FromCurrency");
                FromCurrency.setValue(fromUnit);
                FromCurrency.setType(String.class);
                request.addProperty(FromCurrency);

                PropertyInfo ToCurrency = new PropertyInfo();
                ToCurrency.setName("ToCurrency");
                ToCurrency.setValue(toUnit);
                ToCurrency.setType(String.class);
                request.addProperty(ToCurrency);

                  3.Create a SOAP Envelope using      theorg.ksoap2.serialization.SoapSerializationEnvelope class.
                   SoapSerializationEnvelope envelope = new   SoapSerializationEnvelope(
                        SoapEnvelope.VER11);       
                  envelope.setOutputSoapObject(request);
                 4.Create an HTTP Transport request object to deliver the SOAP request to remote web service (org.ksoap2.transport.HttpTransportSE).Here the URL is WSDL url.
                  HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            5.Send the SOAP request over HTTP using the HTTP Transport and SOAP Envelope objects created earlier.Here SOAP_ACTION is URL combination of NAMESPACE AND METHOD_NAME. This call is a synchronous call. Process the web service response (or handle any unexpected errors). 
                    try {
                 androidHttpTransport.call(SOAP_ACTION, envelope);
                           SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
                           s = response.toString();
                           x = Double.parseDouble(s) * Double.parseDouble(value);/*Retrive the converted value of                                                        currency*/
        ….
        }
                catch (Exception e) {
                    e.printStackTrace();

             }