zoukankan      html  css  js  c++  java
  • android 调用.NET WebServices

    下载Ksoap2.jar,

    import  org.ksoap2.SoapEnvelope;
    import org.ksoap2.serialization.*;
    import org.ksoap2.transport.HttpTransportSE;
    import android.os.Handler;

    Handler handler = new Handler() {

    @Override
    public void handleMessage(Message msg) {
    super.handleMessage(msg);
    Bundle bundle= msg.getData();
    String result=bundle.getString("result");

    Toast.makeText(LoginActivity.this,result,Toast.LENGTH_SHORT).show();
    }
    };

    new Thread() {
    public void run() {

    String Namespace = "http://tempuri.org/";
    String MethodName = "UserLogin";
    String WEB_SERVICE_URL = "http://192.168.4.2/myWeb/User.asmx";

    SoapObject request = new SoapObject(Namespace, MethodName);
    // 2、设置调用方法的参数值,如果没有参数,可以省略,


    // 3、生成调用Webservice方法的SOAP请求信息。该信息由SoapSerializationEnvelope对象描述
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
    SoapEnvelope.VER12);
    envelope.bodyOut = request;
    // c#写的应用程序必须加上这句
    envelope.dotNet = true;
    HttpTransportSE ht = new HttpTransportSE(WEB_SERVICE_URL);
    // 使用call方法调用WebService方法
    try {

    ht.call(null, envelope);
    } catch (Exception e) {
    e.printStackTrace();
    }
    try {
    final SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
    if (result != null) {
    Log.d("----收到的回复----", result.toString());


    Message message=new Message();
    Bundle bundle=new Bundle();
    bundle.putString("result",result.toString());
    message.setData(bundle);
    handler.sendMessage(message);


    }


    } catch (Exception e) {
    Log.e("----发生错误---", e.getMessage());
    e.printStackTrace();
    }
    }
    }.start();
  • 相关阅读:
    你不知道的JavaScript(上)this和对象原型(二)
    hihocoder 1566 皇室成员的名字
    csu 1756: Prime
    csu 1770: 按钮控制彩灯实验
    csu 1898: 复盘拉火车
    csu 1901: 赏赐 OR 灾难
    csu 1909: Perfect Chocolate
    csu 1958: 数字游戏
    symfony2 环境搭建笔记
    php preg_match($p, $str, $match)方法简介
  • 原文地址:https://www.cnblogs.com/Chareree/p/6119882.html
Copyright © 2011-2022 走看看