Android+webService的连接
来源:互联网 发布:linux中ps命令 编辑:程序博客网 时间:2024/05/21 18:42
</pre><pre name="code" class="java"><div> <span style="font-size:24px;"> 最近初步在搞android怎么去跟webservice的连接,调用参数返回。在这里发下我运行的源码。已测试,已成功! </span></div><div></div>
<span style="font-size:18px;">import android.widget.EditText;public class LQserviceActivity extends Activity {/** Called when the activity is first created. */private Button button;private EditText editText;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);button = (Button) findViewById(R.id.button);editText = (EditText) findViewById(R.id.edit);button.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {String show = editText.getText().toString();String showMessage = "";try {showMessage = getPhoneInfo(show);editText.setText(showMessage);} catch (XmlPullParserException e) {} catch (IOException e) {e.printStackTrace();}}});}public String getPhoneInfo(String phoneName) throws IOException,XmlPullParserException {// 获取URLString URL = "http://61.143.165.38/wlss.asmx";// 返回的查询结果String result = null;// 调用webservice接口的命名空间String namespace = "http://61.143.165.38/";// 调用的方法名String methodName = "HelloWorld";// webservice中SOAPAction的地址String SOAP_ACTION = "http://www.1008656.com/HelloWorld";// 获得返回请求对象SoapObject request = new SoapObject(namespace, methodName);// 设置需要返回请求对象方法的参数// request.addProperty("moblieCode",phoneName);// request.addProperty("userId","");// 设置soap的版本SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);// 设置是否调用的是dotNet开发的,这里如果设置为TRUE,那么在服务器端将获取不到参数值(如:将这些数据插入到数据库中的话)envelope.dotNet = true;envelope.bodyOut = request;AndroidHttpTransport hts = new AndroidHttpTransport(URL);// web service请求hts.call(SOAP_ACTION, envelope);// hts.call(null,envelope);// 得到返回结果Object o = envelope.getResponse();result = o.toString();return result;}}</span>
<span style="font-size:18px;"><strong>main.xml的源码如下:</strong></span>
<span style="font-size:18px;"><?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" > <!-- android:text="webservice的调用" --> <Button android:id="@+id/button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="点击" /> <EditText android:id="@+id/edit" android:layout_width="fill_parent" android:layout_height="wrap_content" /></LinearLayout></span>
0 0
- Android+webService的连接
- Android连接webservice笔记
- android 连接webservice (SoapObject )
- android连接webservice
- Android通过Webservice连接数据库
- Android通过Ksoap连接webservice
- android studio + .Net webservice 连接
- (android)用ksoap2连接webservice
- Android利用ksoap2方式连接webservice
- android 利用ksoap2方式连接webservice
- 转载 android 利用ksoap2方式连接webservice
- android 利用ksoap2方式连接webservice
- android 环境下 ksoap2 连接webservice.
- android用webservice连接sqlserver数据库
- android用webservice连接sqlserver数据库 .
- Android通过webservice连接sqlserver数据库
- Android通过webservice连接SQLServer 教程
- Android WebService(基于SOAP协议) 连接方法
- 重写console.log 实现自己的逻辑
- android app中context的个数
- mssql2000查询日期是否在数据库记录的日期范围
- 微信营销的基础是用心交朋友你知道吗?
- 把EXCEL数据导入到SQL SERVER数据库中
- Android+webService的连接
- The potential utilization value of vertical mill
- iOS 6.0中UIViewController被弃用的一些方法
- HDU-1005-Number Sequence(Java版+考虑周期+恶心水题!)
- 什么叫对象序列化
- .NET出现频率非常高的笔试题
- Linux内核课程学习心得
- 手机浏览器无法访问自己部署的tomcat程序(WEB项目)
- ArcGIS 10.2 JavaScript API本地部署离线开发环境