30调用服务



package com.test.weather;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

/**
 * 查询手机号码归属地
 * @author Leo
 *
 */
public class WeatherActivity extends Activity {
 private EditText number = null;
 private Button search = null;
 private TextView result = null;

 //命名空间
 private static final String NAMESPACE = "http://WebXml.com.cn/";
 //方法名字
 private static final String METHOD_NAME = "getMobileCodeInfo";
 //终点地址
 private static final String ENDPOINT = "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx";
 //服务动作
 private static final String SOAP_ACTION = "http://WebXml.com.cn/getMobileCodeInfo";

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  number = (EditText) findViewById(R.id.number);
  result = (TextView) findViewById(R.id.result);
  search = (Button) findViewById(R.id.search);
  search.setOnClickListener(new View.OnClickListener() {

   public void onClick(View v) {
    // TODO Auto-generated method stub
    String key = number.getText().toString().trim();
    SoapObject detail = getInformation(key);
    String string = detail.getProperty(0).toString();
    result.setText(string);
   }
  });
 }

 private SoapObject getInformation(String key) {
  //定义一个SoapObject对象并初始化命名空间和方法名字
  SoapObject rpc = new SoapObject(NAMESPACE, METHOD_NAME);
  //添加所需属性
  rpc.addProperty("mobileCode", key);
  rpc.addProperty("userID", "");
  //生成SOAP请求信息
  SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
    SoapEnvelope.VER10);
  envelope.bodyOut = rpc;
  envelope.dotNet = true;
  envelope.setOutputSoapObject(rpc);
  //创建HttpTransportSE对象进行请求
  HttpTransportSE transport = new HttpTransportSE(ENDPOINT);
  try {
   transport.call(SOAP_ACTION, envelope);
  } catch (Exception e) {
   e.printStackTrace();
  }
  //得到结果并返回
  return (SoapObject) envelope.bodyIn;
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

柠檬味的黄

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值