Android开发调用webservice方式

添加ksoap2-android-assembly-3.6.3-jar-with-dependencies.jar包
创建KsoapHelper类

package Model;

import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.ArrayList;

public class KsoapHelper {
    public static int timeOut = 30000;
    public static String webServiceUrl;
    public static String nameSpace;
    public static int soapVersion = 120;
    private KsoapHelper() {
    }

    public static void initKsoapHelper(String _webServiceUrl, String _nameSpace) {
        initKsoapHelper(timeOut, _webServiceUrl, _nameSpace, soapVersion);
    }

    public static void initKsoapHelper(String _webServiceUrl, String _nameSpace, int _version) {
        initKsoapHelper(timeOut, _webServiceUrl, _nameSpace, _version);
    }

    public static void initKsoapHelper(int _timeOut, String _webServiceUrl, String _nameSpace, int _version) {
        nameSpace = _nameSpace;
        webServiceUrl = _webServiceUrl;
        timeOut = _timeOut;
        soapVersion = _version;
    }

    public static SoapObject GetSoapObject(String methodName) {
        SoapObject object = new SoapObject(nameSpace, methodName);
        return object;
    }

    public static SoapObject GetSoapObject(String nameSpace, String methodName) {
        SoapObject object = new SoapObject(nameSpace, methodName);
        return object;
    }

    public static Object GetResult(SoapObject object, boolean isSimple) throws IOException, XmlPullParserException {
        SoapSerializationEnvelope sSEnvelope = new SoapSerializationEnvelope(120);
        sSEnvelope.bodyOut = object;
        sSEnvelope.dotNet = true;
        HttpTransportSE httpTransSE = new HttpTransportSE(webServiceUrl, timeOut);
        httpTransSE.debug = true;
        httpTransSE.call((String)null, sSEnvelope);
        SoapObject result;
        if (isSimple) {
            result = null;
            Object simpleResult = sSEnvelope.getResponse();
            return simpleResult.toString();
        } else {
            ArrayList <String>temp = new ArrayList<>();
            result = (SoapObject)sSEnvelope.bodyIn;
            SoapObject childs = (SoapObject)result.getProperty(0);
            for(int i=0;i<childs.getPropertyCount();i++)
            {
                temp.add(childs.getProperty(i).toString());
            }
           return temp;
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值