目录
- 1.导入pom
- 2.编写测试类TestWsdl
- 3.运行main结果
1.导入pom
<!-- JAX-WS API -->
<dependency>
<groupId>Javax.XML.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency&g编程t;
<!-- JAX-WS Runtime -->
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.3.1</version>
</dependency>
<!-- 工具集 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.15</version>
</dependency>
2.编写测试类TestWsdl
import cn.hutool.http.webservice.SoapClient;
import org.dom4j.Documen编程t;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import javax.xml.soap.SOAPMessage;
/**
* 测试调用wsdl接口
* @author laijiangfeng
* @date 2024/9/27 9:51
*/
public class TestWsdl {
public static void main(String[] args) throws Exception {
// 创建SoapClient实例 wsdl协议请求地址:http://xxx.cn/services/GanSuInterface (去掉?wsdl)
SoapClient client = SoapClient.create("http://xxx.cn/services/GanSuInterface")
// 设置方法名和命名空间(命名空间url:http://webservice.xxx.xxx ,方法名:getSydwjsonList)
// tns 命名空间targetNameswww.devze.compace,没有命名空间时直接写方法名即可
.setMethod("tns:getSydwJsonList", "http://webservice.xxx.xxx")
// 设置参数(最后的false参数表示参数不加命名空间的前缀web)
python .setParam("in0", "afe9cff39173ff8901917a54c90e448d", false);
//获取SOAPMessage实例(此步作用是输出请求的XML参数,实际开发并不需要)
SOAPMessage message = client.getMessage();
System.out.println(client.getMsgStr(true));
// 发送请求(true表示输出的结果格式化处理)
String send = client.send(true);
Document document = DocumentHelper.parseText(send);
Element root = document.getRootElement();
String value = root.getStringValue();
System.out.println(send);
System.out.println(value);
}
}
命名空间url不同的接口可能不一样自己通过访问接口地址获取
3.运行main结果


上面第一部分是请求body、第二部分是返回的结果body、第三部分是解析后的结果json
到此这篇关于java 调用wsphpdl协议接口简单实用方法最新推荐的文章就介绍到这了,更多相关java 调用wsdl接口内容请搜索编程客栈(www.devze.com)以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程客栈(www.devze.com)!
加载中,请稍侯......
精彩评论