http://www.pudn.com/downloads300/sourcecode/comm/android/detail1341124.html
MainActivity.java
package com.lp.demo;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
private static String LOG_TAG = "MobileCodeInfo";
private static boolean DEBUG = false;
private static final String NAMESPACE = "http://WebXml.com.cn/";
private static String URL = "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx";
private static final String METHOD_NAME = "getMobileCodeInfo";
private static String SOAP_ACTION = "http://WebXml.com.cn/getMobileCodeInfo";
private EditText et_input_number;
private Button bt_query;
private TextView tv_show;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findView();
bt_query.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tv_show.setText(getMobileCodeInfo(et_input_number.getText().toString())) ;
}
});
}
private void findView(){
et_input_number=(EditText)findViewById(R.id.EditText01);
bt_query=(Button)findViewById(R.id.Button01);
tv_show=(TextView)findViewById(R.id.TextView01);
}
public String getMobileCodeInfo(String mobileNumber){
String MobileCodeInfo = null;
try {
Log.d("test","------------------------->"+MobileCodeInfo);
//���岢��ʼ��SoapObject
SoapObject rpc = new SoapObject(NAMESPACE, METHOD_NAME);
//������� (������string������ֵobject)
rpc.addProperty("mobileCode", mobileNumber);
//��b����ͨ��
AndroidHttpTransport ht = new AndroidHttpTransport(URL);
ht.debug = true;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.bodyOut = rpc;
envelope.dotNet = true;
envelope.setOutputSoapObject(rpc);
ht.call(SOAP_ACTION, envelope);
debug(LOG_TAG, "DUMP>> " + ht.requestDump);
debug(LOG_TAG, "DUMP<< " + ht.responseDump);
SoapObject result = (SoapObject) envelope.bodyIn;
Log.d("test","--------------------------->"+result);
MobileCodeInfo = result.getProperty("getMobileCodeInfoResult").toString();
Log.d("test","--------------------------->"+MobileCodeInfo);
// MobileCodeInfo = "��ѯ���" +detail.getProperty(0).toString();
Log.d("test","------------------------>");
} catch (Exception e) {
Log.e("Exception is ","---->"+e);
MobileCodeInfo = "��������ȷ���ֻ����!";
}
return MobileCodeInfo;
}
private static void debug(String tag, String msg) {
if (DEBUG) Log.d(tag, msg);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lp.demo"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainActivity"
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>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="输入手机号码:"/>
<LinearLayout android:id="@+id/LinearLayout01" android:layout_height="wrap_content" android:layout_width="fill_parent"><EditText android:id="@+id/EditText01" android:layout_height="wrap_content" android:layout_width="200px"></EditText>
<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="查询"></Button>
</LinearLayout>
<TextView android:id="@+id/TextView01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_margin="10px"></TextView>
</LinearLayout>