soap-ws Java开源框架,github上是这样解释的:
soap-ws ,A lightweight and easy-to-use Java library to handle SOAP on a purely XML level.
github列举了一些使用方法,地址:https://github.com/reficio/soap-ws。
在使用的过程中,需要通过wsdl地址获取到wsdl中定义的所有方法,也就是operation。wsdl中定义Operation的地方有2个:①portType节点;②binding节点。 一般来说,这2个节点的operation是完全一样的。不过通过SOAPUI访问wsdl,获取的是binding节点中的所有operation。如果2个节点的operation都一样获取哪个节点都可以。
看了一下示例代码,
soap-ws是通过以下的方法获取的operation。
SoapOperation operation = builder.operation().soapAction("http://www.webserviceX.NET/ConversionRate").find();
上述方法必须要知道Action的定义,大部分wsld中的Operation都是没有定义action的。所以通过以上方法不行。
查看接口SoapBuilder,定义了获取operation的方法,获取的是binding节点的所有operation。
public interface SoapBuilder {List<SoapOperation> getOperations();}
那通过wsdl怎么用到接口SoapBuilder的getOperations()呢?
参考示例SoapBuilder builder = *wsdl.binding()*.localPart("CurrencyConvertorSoap").find();
类Wsdl中提供了获取所有binding的方法public List<QName> getBindings()
完整代码如下:
public static List<String> getBindingOperations(String wsdlUrl) {
List<String> operationList = new ArrayList();
List<SoapOperation> soapOperationList = new ArrayList();
Wsdl parser = Wsdl.parse(wsdlUrl);
List<QName> bindQnames = parser.getBindings();
for (QName qName : bindQnames) {
SoapBuilder soapBuilder = parser.binding().localPart(qName.getLocalPart()).find();
soapOperationList.addAll(soapBuilder.getOperations());
}
for (SoapOperation soapOperation : soapOperationList) {
operationList.add(soapOperation.getOperationName());
}
return operationList;
}
以获取天气为例,测试结果: wsdlUrl = “http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl“;
[getSupportCity, getSupportProvince, getSupportDataSet, getWeatherbyCityName, getWeatherbyCityNamePro, getSupportCity, getSupportProvince, getSupportDataSet, getWeatherbyCityName, getWeatherbyCityNamePro, getSupportCity, getSupportProvince, getSupportDataSet, getWeatherbyCityName, getWeatherbyCityNamePro, getSupportCity, getSupportProvince, getSupportDataSet, getWeatherbyCityName, getWeatherbyCityNamePro]