soap-ws 获取wsdl中所有方法 (三)

3. 两种方法比较

测试方法

    @Test
    public void test2() {
        String wsdlUrl = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl";
        long s1=System.currentTimeMillis();
        System.out.println(getBindingOperations(wsdlUrl));
        long e1=System.currentTimeMillis();
        System.out.println("getBindingOperations "+(e1-s1));//1707ms
        long s2=System.currentTimeMillis();
        System.out.println(getOperationByUrl(wsdlUrl));
        long e2=System.currentTimeMillis();
        System.out.println("getOperationByUrl "+(e2-s2));//199ms
        System.out.println(Arrays.equals(getBindingOperations(wsdlUrl).toArray(),getOperationByUrl(wsdlUrl).toArray()));
    }

测试结果:

[getSupportCity, getSupportProvince, getSupportDataSet, getWeatherbyCityName, getWeatherbyCityNamePro, getSupportCity, getSupportProvince, getSupportDataSet, getWeatherbyCityName, getWeatherbyCityNamePro, getSupportCity, getSupportProvince, getSupportDataSet, getWeatherbyCityName, getWeatherbyCityNamePro, getSupportCity, getSupportProvince, getSupportDataSet, getWeatherbyCityName, getWeatherbyCityNamePro]
getBindingOperations **1123**
[getSupportCity, getSupportProvince, getSupportDataSet, getWeatherbyCityName, getWeatherbyCityNamePro, getSupportCity, getSupportProvince, getSupportDataSet, getWeatherbyCityName, getWeatherbyCityNamePro, getSupportCity, getSupportProvince, getSupportDataSet, getWeatherbyCityName, getWeatherbyCityNamePro]
getOperationByUrl **35**
false

执行时间上差距很大,原因是第一种方法每次都是新建一个对象。

    static SoapOperationBuilder create(SoapBuilder builder, Binding binding, BindingOperation operation, String soapAction) {
        String bindingInputName = operation.getBindingInput() != null ? operation.getBindingInput().getName() : null;
        String bindingOutputName = operation.getBindingOutput() != null ? operation.getBindingOutput().getName() : null;
        return new SoapOperationImpl(builder, binding.getQName(), operation.getName(), bindingInputName, bindingOutputName,
                SoapUtils.normalizeSoapAction(soapAction));
    }

第二中方法获取到的Binding节点和获取portType节点比较。

    @Test
    public void test03(){
        String wsdlUrl = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl";
        long s1=System.currentTimeMillis();
        System.out.println(getAllBindingOperation(wsdlUrl));
        long e1=System.currentTimeMillis();
        System.out.println("getAllBindingOperation "+(e1-s1));//480ms
        long s2=System.currentTimeMillis();
        System.out.println(getOperationByUrl(wsdlUrl));
        long e2=System.currentTimeMillis();
        System.out.println("getOperationByUrl "+(e2-s2));//281ms
        System.out.println(Arrays.equals(getAllBindingOperation(wsdlUrl).toArray(),getOperationByUrl(wsdlUrl).toArray()));
    }

测试结果

[getSupportCity, getSupportProvince, getSupportDataSet, getWeatherbyCityName, getWeatherbyCityNamePro, getSupportCity, getSupportProvince, getSupportDataSet, getWeatherbyCityName, getWeatherbyCityNamePro, getSupportCity, getSupportProvince, getSupportDataSet, getWeatherbyCityName, getWeatherbyCityNamePro, getSupportCity, getSupportProvince, getSupportDataSet, getWeatherbyCityName, getWeatherbyCityNamePro]
getAllBindingOperation 265
[getSupportCity, getSupportProvince, getSupportDataSet, getWeatherbyCityName, getWeatherbyCityNamePro, getSupportCity, getSupportProvince, getSupportDataSet, getWeatherbyCityName, getWeatherbyCityNamePro, getSupportCity, getSupportProvince, getSupportDataSet, getWeatherbyCityName, getWeatherbyCityNamePro]
getOperationByUrl 39
false

综上,获取portType节点的operation时间最快。生产环境推荐获取binding节点的信息。

转载于:https://my.oschina.net/wuxinshui/blog/847526

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值