微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ksoap2调用webservice

package com.fei.test;

import org.ksoap2.soapEnvelope;
import org.ksoap2.serialization.soapObject;
import org.ksoap2.serialization.soapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

public class Test {
        public void getRemoteInfo(String phonesec) {  
        // 命名空间  
        String nameSpace = "http://WebXml.com.cn/";  
        // 调用方法名称  
        String methodName = "getMobileCodeInfo";  
        // EndPoint  
        String endPoint = "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx";  
        // SOAP Action  
        String soapAction = "http://WebXml.com.cn/getMobileCodeInfo";  
  
        // 指定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.VER10);  
  
        envelope.bodyOut = rpc;  
        // 设置是否调用的是dotNet开发的WebService  
        envelope.dotNet = true;  
        // 等价于envelope.bodyOut = rpc;  
        envelope.setoutputSoapObject(rpc);  
  
        HttpTransportSE transport = new HttpTransportSE(endPoint);  
        try {  
            // 调用WebService  
            transport.call(soapAction,envelope);  
        } catch (Exception e) {  
            e.printstacktrace();  
        }  
  
        // 获取返回的数据  
        SoapObject object = (SoapObject) envelope.bodyIn;  
        // 获取返回的结果  
        String result = object.getProperty(0).toString();  
  
        // 将WebService返回的结果显示在TextView中  
        resultView.setText(result);  
    }  
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐