如何从android应用程序向SOAP Webservice发送数据



大家好,我是android开发新手。我已经创建了一个soap webservices,并创建了一个android应用程序来获取用户名和密码,如下所示:

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>

因此,我将从user获得两个字段(用户名和密码)。我想将数据发布或发送到具有

的SOAP web服务
url: "http://localhost:8100/ws/hello?wsdl"
and Qname: "http://Common.Hospital/", "HelloWorldImplService".
谁能帮我解决我的问题?

下面是向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;
}

查看此库https://code.google.com/p/ksoap2-android/。它是一个轻量级的SOAP客户机实现。但是,我建议您使用Rest而不是SOAP。

最新更新