Android 调用webservice

 
new Thread(){
@Override
public void run()
{
Looper.prepare();
if (getInfo()){
Intent intent = new Intent();
intent.setClass(MainActivity.this, DetailActivity.class);
startActivity(intent);
}else{
Toast.makeText(MainActivity.this, "用户名或密码错误", Toast.LENGTH_SHORT).show();
}
Looper.loop();
}
}.start();
/**
 * webService
 */
public boolean getInfo() {
    // 命名空间
    String nameSpace = "http://tempuri.org/";
    // 调用的方法名称
    String methodName = "getSystemDate";
    // EndPoint
    //String url = "http://localhost/Webservice/service.asmx?WSDL";
    String url = "http://10.0.2.2/Webservice/service.asmx?WSDL";
    // SOAP Action
    String soapAction = "http://tempuri.org/getSystemDate";

    // 指定WebService的命名空间和调用的方法名
    SoapObject rpc = new SoapObject(nameSpace, methodName);

    // 设置需调用WebService接口需要传入的两个参数mobileCode、userId
    //rpc.addProperty("mobileCode", phoneSec);
    //rpc.addProperty("userId", "");

    // 生成调用WebService方法的SOAP请求信息,并指定SOAP的版本
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

    envelope.bodyOut = rpc;
    // 设置是否调用的是dotNet开发的WebService
    envelope.dotNet = true;
    // 等价于envelope.bodyOut = rpc;
    envelope.setOutputSoapObject(rpc);

    HttpTransportSE transport = new HttpTransportSE(url);
    try {
        // 调用WebService
        transport.call(soapAction, envelope);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // 获取返回的数据
    SoapObject object = (SoapObject) envelope.bodyIn;
    // 获取返回的结果
    String result = object.getProperty(0).toString();
    return false;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值