springboot
调用asmx
后缀 webservice
接口
引入依赖
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>3.2.5</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
使用
JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
// wsdlUrl webservice地址,加上?wsdl后缀
Client client = clientFactory.createClient(wsdlUrl);
// name_space 命名空间
QName qName = new QName(name_space, "GetInfo");
try {
//参数数组
Object[] param = new Object[]{...参数};
Object[] res = client.invoke(qName, param);
// 处理结果res[0]
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(res[0]));
List<A> aList = JSONObject.parseArray(jsonObject.get("data").toString(),A.class);
// 业务
} catch (Exception e) {
e.printStackTrace();
}
-
名词解释
// name_space就是xmlns的值 <soap:Body> <GetInfo xmlns="http://aaa.org/"> <ticket>string</ticket> </GetInfo> </soap:Body>
用作个人记录,希望对你也有帮助