简体   繁体   English

如何从Android应用程序将数据发送到SOAP Web服务?

[英]How to send data to SOAP Webservice from an android application?

Hi I am new to android development. 嗨,我是android开发的新手。 I have created a soap webservices and created a android application to get username and password as shown below: 我创建了一个肥皂网络服务并创建了一个Android应用程序来获取用户名和密码,如下所示:

Firstscreen.xml: 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 我想将数据发布或发送到具有以下功能的SOAP Web服务:

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. 提前致谢。

And here is a sample code to send request to webservice : 这是将请求发送到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;
}

Check out this library https://code.google.com/p/ksoap2-android/ . 查看此库https://code.google.com/p/ksoap2-android/ It is a light-weight SOAP client implementation. 它是一个轻量级的SOAP客户端实现。 However, I would recommend you to use Rest instead of SOAP. 但是,我建议您使用Rest而不是SOAP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM