您的位置:首页 >SpringBoot如何使用axis调用webservice接口
发布于2023-05-10 阅读(0)
扫一扫,手机访问

通过度娘等方式,个人理解为变相的soap协议加xml工单处理,
qq 在线验证接口:
www.webxml.com.cn/webservices…
其他可测试接口:
email电子邮箱地址接口: www.webxml.com.cn/WebServices…
全国天气情况接口:
www.webxml.com.cn/WebServices…
在接口后面加:/wsdl www.webxml.com.cn/webservices…
访问查看然后找到下图中定义的内容:注意使用关联key找到对应的必要使用的参数。

<!-- https://mvnrepository.com/artifact/org.apache.axis/axis --> <dependency> <groupId>org.apache.axis</groupId> <artifactId>axis</artifactId> <version>1.4</version> </dependency> <!-- https://mvnrepository.com/artifact/wsdl4j/wsdl4j --> <dependency> <groupId>wsdl4j</groupId> <artifactId>wsdl4j</artifactId> <version>1.6.2</version> </dependency> <!-- 解决cell 转换问题--> <!-- https://mvnrepository.com/artifact/javax.xml/jaxrpc-api --> <dependency> <groupId>javax.xml</groupId> <artifactId>jaxrpc-api</artifactId> <version>1.1</version> </dependency> <!-- 解析调用结果以及数据转换包--> <!-- https://mvnrepository.com/artifact/commons-discovery/commons-discovery --> <dependency> <groupId>commons-discovery</groupId> <artifactId>commons-discovery</artifactId> <version>0.2</version> </dependency>
@Test
public void testWebService() {
try {
//wsdl地址
String endpoint = "http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx";
//命名空间
String namespace = "http://WebXml.com.cn/";
//服务名
String serviceName = "qqOnlineWebService";
//方法名
String methodName = "qqCheckOnline";
//soapAction
String soapAction = "http://WebXml.com.cn/qqCheckOnline";
Service service = new Service();
Call call = (Call) service.createCall();
//设置响应超时
call.setTimeout(3000);
//设置地址
call.setTargetEndpointAddress(new java.net.URL(endpoint));
//设置方法名
call.setOperationName(new QName(namespace, methodName));
//设置参数
call.addParameter(new QName(namespace, "qqCode")
, org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
//设置返回类型
call.setReturnType(XMLType.XSD_SCHEMA);
//启用soap
call.setUseSOAPAction(true);
//设置soapAction
call.setSOAPActionURI(soapAction);
//设置服务名
SOAPService soapService = new SOAPService();
soapService.setName(serviceName);
call.setSOAPService(soapService);
Schema result = (Schema) call.invoke(new Object[]{"xxxxx"});
for (int i = 0; i < result.get_any().length; i++) {
System.out.println(result.get_any()[i]);
}
} catch (Exception e) {
log.error("ddd", e);
}
}对于以上代码,我这边吐槽一下,网上其实很多这个的例子但是实际调用的时候会出问题,注意点:
设置参数

获取结果

xxxx需要填写真实的QQ号码
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
正版软件
正版软件
正版软件
正版软件
正版软件
1
2
3
7
9