0

Hi I am new to android development. I have created a soap webservices and created a android application to get username and password as shown below:

Firstscreen.xml:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:stretchColumns="1" >

    <TableRow
        android:gravity="center"
        android:paddingTop="45dp" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint"
            android:text="@string/username" />

        <!-- Text Editor -->

        <EditText
            android:id="@+id/enterusername"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="text" />
    </TableRow>

    <TableRow>

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint"
            android:text="@string/password" />

        <!-- Text Editor -->

        <EditText
            android:id="@+id/entertextpassword"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword" />
    </TableRow>

    <TableRow>

        <Button
            android:id="@+id/login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_span="2"
            android:clickable="true"
            android:gravity="center"
            android:text="@string/login" >
        </Button>
    </TableRow>

</TableLayout>

So, I will get two fields(username and password) from user. I want to post or send the data to a SOAP webservice which has

url: "http://localhost:8100/ws/hello?wsdl"
and Qname: "http://Common.Hospital/", "HelloWorldImplService".

Can anybody help me to get resolved my problem. Thanks in advance.

Vishnu
  • 97
  • 3
  • 11

2 Answers2

1

And here is a sample code to send request to webservice :

public class SoapRequest {
private static final String SOAP_ACTION = "xxx";
private static final String METHOD_NAME = "xxx";
private static final String NAMESPACE = "xxx";
private static final String URL = "url of the webservice";

public static SoapObject soap() throws IOException, XmlPullParserException {
    SoapObject request = new SoapObject (NAMESPACE, METHOD_NAME);

/* Here you can add properties to your requests */
    PropertyInfo pi1 = new PropertyInfo();
    pi1.name = "xxx";
    pi1.type = String.class;
    request.addProperty(pi1, "xxx");

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.debug = true; 
    androidHttpTransport.call(SOAP_ACTION, envelope);
    SoapObject soapResult = (SoapObject) envelope.bodyIn;
    return soapResult;
}
Jonsmoke
  • 674
  • 7
  • 17
  • Hi thanks for the reply. Can you please tell, where i shoud write the above class whether in mainActivity or seperate class. If seperate class, then how to call this class in mainactivity. I am sorry if it is a stupid question. – Vishnu Aug 01 '14 at 10:23
  • Just create a new class in your package, copy/paste this (try to understand a bit also !!) then you have to create a SoapObject, and call **object = SoapRequest.soap();**. Of course this is just a sample code that you will have to adapt to your needs afterward ! – Jonsmoke Aug 01 '14 at 10:28
0

Check out this library https://code.google.com/p/ksoap2-android/ . It is a light-weight SOAP client implementation. However, I would recommend you to use Rest instead of SOAP.

Vinh Vo
  • 161
  • 2
  • 7