webService访问数据的具体实现方法
来源:互联网 发布:ubuntu my.cnf位置 编辑:程序博客网 时间:2024/06/05 06:07
代码编写步骤
创建HttpTransportSE传输对象
创建SoapSerializationEnvelope对象(设定soap协议版本号)设置发送给服务器的数据bodyout属性
实例化SoapObject对象
设置调用方法的参数值,如果没有参数,可以省略
设置支付语言
调用HttpTransportSE对象的call()方法
获取服务器响应返回的SOAP消息(bodyin)
具体实现
public class WebServiceActivity extends Activity implements View.OnClickListener{
public final String TAG = getClass().getSimpleName();
EditText editText ;
Button button ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webservice);
initView();
}
private void initView(){
editText = (EditText) findViewById(R.id.edittext_webservice);
button = (Button) findViewById(R.id.btn_webservice);
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_webservice:
getContent(editText.getText().toString().trim());
break;
}
}
// 查询手机号码归属地
private void getContent(final String content){
new Thread(new Runnable() {
@Override
public void run() {
if(!TextUtils.isEmpty(content)){
//定义方法名称
final String name = "GetMobileOwnership" ;
//定义命名空间
final String namespace = "http://www.36wu.com/";
//定义url
final String url = "http://web.36wu.com/MobileService.asmx?WSDL" ;
// namespace + name
final String soapAction = namespace + name ;
// 设置命名空间,及访问的方法名
SoapObject soapObject = new SoapObject(namespace,name);
soapObject.addProperty("mobile",content);
soapObject.addProperty("format","xml");
soapObject.addProperty("authkey","d117ac0e665848cd8162c3539a6ddef0");
// 创建 HttpTransportSE 对象
HttpTransportSE httpTransportSE = new HttpTransportSE(url);
// 创建 SoapSerializationEnvelope 对象
SoapSerializationEnvelope soapSerializationEnvelope = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER11);
//支持 c# 语言
soapSerializationEnvelope.dotNet = true ;
// 把传递参数 放到 SoapSerializationEnvelope 对象里面
soapSerializationEnvelope.bodyOut = soapObject ;
try {
//发送请求
httpTransportSE.call(soapAction,soapSerializationEnvelope);
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
//得到ws 返回的数据 (取数据)
SoapObject soapObjectResult = (SoapObject) soapSerializationEnvelope.bodyIn ;
Log.e(TAG,"soapObjectResult start " + soapObjectResult);
SoapObject getMobileOwnershipResult = (SoapObject) soapObjectResult.getProperty("GetMobileOwnershipResult") ;
SoapObject data = (SoapObject) getMobileOwnershipResult.getProperty("data") ;
Log.e(TAG,"soapObjectResult nor" + getMobileOwnershipResult);
Log.e(TAG,"soapObjectResult " + getMobileOwnershipResult);
Log.e(TAG,"soapObjectResult " + getMobileOwnershipResult.getProperty(0));
Log.e(TAG,"soapObjectResult " + getMobileOwnershipResult.getProperty(1));
Log.e(TAG,"soapObjectResult " + data.getProperty("corp"));
}
}
}).start();
}
}
- webService访问数据的具体实现方法
- android 调用webService的具体方法
- Java访问WebService返回XML数据的方法
- android 访问WebService的方法
- Android 访问WebService的方法
- 分页的具体实现方法
- JS验证数据有效性的具体方法
- 访问数据的方法
- flex访问同一个webService的不同方法
- FieldInfos的write方法的具体实现
- String的lequals方法的具体实现
- WebService访问数据
- 用JSPGen实现JSP数据分页显示的具体方法(支持4种常见数据库)
- MySql批量插入多条数据的一种具体实现方法
- 代码清单7-4是一个比较完整的数据访问组件,下面分析这些代码的具体实现。
- java客户端访问.net实现的WebService
- 具体java打印方法的实现
- C#委托的具体实现方法
- 太平天国后期战斗力为何断崖…
- selenium webdriver python的路径报错的解决方法-WIN7以上系统
- 很多人都不知道的监听微信、支付宝等移动app及浏览器的返回、后退、上一页按钮的事件方法
- 《大话数据结构》第1章 数据结构绪论 1.2 你数据结构怎么学的?
- android 图标制作
- webService访问数据的具体实现方法
- 如何将代码上传到淘宝code
- Maven创建一个聚合工程(框架)
- maven web项目的tomcat启动,运行,调试问题
- bzoj2302 [HAOI2011]Problem c
- 【源码解析】JDK源码之LinkedHashMap
- 大数删除k位是否能整除3,MG loves apple(HDU)
- 警惕常见6种伤肾食物:煎炸食物不能吃!
- Baxter机器人在ros下,机械臂采集末端姿态并且轨迹还原