android连接webservice

// 命名空间
    final String SERVICE_NS = getString(R.string.NameSpace);
    // 调用的方法名称
    String methodName = "ConfirmApplication";
    final String SOAP_ACTION = getString(R.string.NameSpace) + methodName;
    //用来定义消息请求的地址,也就是消息发送到哪个操作
    final String SERVICE_URL = getString(R.string.WebServiceURL);
    // 指定WebService的命名空间和调用的方法名
    SoapObject soapObject = new SoapObject(SERVICE_NS, methodName);
    // 设置调用WebService接口需要传入的参数
    soapObject.addProperty("TruckCode",Ed_cph);//车牌号
    soapObject.addProperty("UserId",tv_userId);//账号

    // 生成调用WebService方法的SOAP请求信息,并指定SOAP的版本
    final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;//true是.net false是java
    envelope.bodyOut = soapObject;

    final HttpTransportSE ht = new HttpTransportSE(SERVICE_URL);
    ht.debug = true;

    new Thread() {
        @Override
        public void run() {
            try {
                //调用WebService
                ht.call(SOAP_ACTION, envelope);
                Message msg = new Message();
                if (envelope.getResponse() != null) {
                    SoapObject so = (SoapObject) envelope.bodyIn;
                    //定义好的私有静态变量,在Handler中进行解析、显示
                    result= so.getProperty(0).toString();//获取WebService返回值(此处为字符串)
                    msg.what = 0;
                } else {
                    msg.what = 1;
                }
                handler.sendMessage(msg);
            } catch (Exception ex) {
                Message msg = new Message();
                msg.what = -1;
                handler.sendMessage(msg);
                System.out.println(ex.getMessage());
            }
        }
    }.start();

需要包:https://pan.baidu.com/s/1bc5lyItJOijGrIHxkX2S1Q 提取码:zkbp
关于导包:https://blog.csdn.net/zhw1551706847/article/details/77709142

回到主线程:https://blog.csdn.net/lzx46100211/article/details/89517754
关于解析:https://blog.csdn.net/lzx46100211/article/details/89380858

webservice中怎么发送json:

你可能感兴趣的:(Android)