soap-ws获取wsdl中的所有的接口方法

示例wsdl文件如下,生成的过程可以参考https://www.cnblogs.com/chenyun-/p/11502446.html

 <definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://impl.chenyun.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://impl.chenyun.com/" name="WsImplService">
<types>
<xsd:schema>
<xsd:import namespace="http://impl.chenyun.com/" schemaLocation="http://localhost:8081/Webservice?xsd=1"/>
</xsd:schema>
</types>
<message name="sayname2">
<part name="parameters" element="tns:sayname2"/>
</message>
<message name="sayname2Response">
<part name="parameters" element="tns:sayname2Response"/>
</message>
<message name="sayname">
<part name="parameters" element="tns:sayname"/>
</message>
<message name="saynameResponse">
<part name="parameters" element="tns:saynameResponse"/>
</message>
<portType name="WsImpl">
<operation name="sayname2">
<input wsam:Action="http://impl.chenyun.com/WsImpl/sayname2Request" message="tns:sayname2"/>
<output wsam:Action="http://impl.chenyun.com/WsImpl/sayname2Response" message="tns:sayname2Response"/>
</operation>
<operation name="sayname">
<input wsam:Action="http://impl.chenyun.com/WsImpl/saynameRequest" message="tns:sayname"/>
<output wsam:Action="http://impl.chenyun.com/WsImpl/saynameResponse" message="tns:saynameResponse"/>
</operation>
</portType>
<binding name="WsImplPortBinding" type="tns:WsImpl">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="sayname2">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="sayname">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="WsImplService">
<port name="WsImplPort" binding="tns:WsImplPortBinding">
<soap:address location="http://localhost:8081/Webservice"/>
</port>
</service>
</definitions>

通过wsdl地址获取的所有方法,也就是operations,在wsdl文件中定义这些operation的地方是有两处,一处在portType节点,一处是在binding节点处,两处均可以获取到所有的方法,具体有什么差别暂时还没有发现,这里使用的是在binding节点处获取,在portType处获取暂时没有测试,后续可能会更新。

soap-ws的git地址:https://github.com/reficio/soap-ws

在Readme中可以找到Quick-start,根据里面的讲解,我们需要使用的部分需要添加一个依赖和一个仓库(添加仓库是因为还没有添加进maven的核心仓库,文档中有介绍)

pom.xml

 <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.chenyun</groupId>
<artifactId>webservice_test_v5</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>webservice_test_v5</name>
<description>Demo project for Spring Boot</description> <properties>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.reficio</groupId>
<artifactId>soap-builder</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies> <repositories>
<repository>
<id>reficio</id>
<url>http://repo.reficio.org/maven/</url>
</repository>
</repositories> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

至此,准备已经大概完成,下面是介绍核心代码:

getList.java

 /*
* @author:陈云
* @date:2019/9/10
* @description:返回接口列表
*/
package com.chenyun; import org.reficio.ws.builder.SoapBuilder;
import org.reficio.ws.builder.SoapOperation;
import org.reficio.ws.builder.core.Wsdl; import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List; public class getList {
/**
*
* @param wsdlUrl
* @return List<String>接口列表
*/
public static List<String> getBindingOperations(String wsdlUrl) {
List<String> operationList = new ArrayList();
List<SoapOperation> soapOperationList = new ArrayList();
//解析指定的wsdl文件,生成一个wsdl对象
Wsdl parser = Wsdl.parse(wsdlUrl);
//类Wsdl中提供了获取所有binding的方法getBindings()
List<QName> bindQnames = parser.getBindings();
//接口SoapBuilder,定义了获取operation的方法,获取的是binding节点的所有operation。
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;
}
}
WebserviceTestV5Application.java
package com.chenyun;

import org.apache.log4j.BasicConfigurator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import static com.chenyun.getList.getBindingOperations; @SpringBootApplication
public class WebserviceTestV5Application { public static void main(String[] args) {
SpringApplication.run(WebserviceTestV5Application.class, args);
//提供wsdl的值,调用getBindingOperations()
String wsdl = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl";
System.out.println("=====================================");
System.out.println("接口列表:");
for(int i=0;i<getBindingOperations(wsdl).size();i++){
System.out.println("接口" + i + ":"+ getBindingOperations(wsdl).get(i));
}
System.out.println("=====================================");
System.out.println("接口查询结束");
}
}

运行主函数即可获取到结果。

soap-ws获取ws中的所有的接口方法的更多相关文章

  1. 使用JavaScript获取URL中的参数(两种方法)

    本文给大家分享两种方法使用js获取url中的参数,其中方法二是使用的正则表达式方法,大家可以根据需要选择比较好的方法,废话不多说了,直接看详细介绍吧. 方法一: //取url参数 var type = ...

  2. 用JS获取地址栏中的参数的简易方法

    这个方法用起来超级简单,传入参数即可直接获取地址栏中的参数 代码如下 function GetQueryString(name) { var reg = new RegExp("(^|&am ...

  3. JS获取URL中参数值的4种方法

    方法一:正则法 function getQueryString(name) { var reg = new RegExp('(^|&)' + name + '=([^&]*)(& ...

  4. java爬虫系列第三讲-获取页面中绝对路径的各种方法

    在使用webmgiac的过程中,很多时候我们需要抓取连接的绝对路径,总结了几种方法,示例代码放在最后. 以和讯网的一个页面为例: xpath方式获取 log.info("{}", ...

  5. scala中获取Map中key和value的方法

    val scores=Map("Alice"->10,"Bob"->3,"Cindy"->8) // 获取所有的key v ...

  6. shell脚本获取文件中key/value的小方法

    方法有N种,awk.sad.grep.cut... 以上几种方式不写了,就写两个不太常用到的. 废话少说,直接上代码: cat a.txt aa.gif=aaaa.gif bb.gif=bbbb.gi ...

  7. Javascript获取数组中的最大值和最小值方法汇总

    方法一 sort()方法 b-a从大到小,a-b从小到大 var max2 = arr.sort(function(a,b){ return b-a; })[0]; console.log(max2) ...

  8. vue2 在mounted函数无法获取prop中的变量的解决方法

    props: { example: { type: Object, default() { }, }, }, watch: { example: function(newVal,oldVal){ // ...

  9. ArcGIS Engine中如何获取Map中已经选择的要素呢

    1.使用IEnumFeturea对象获取map中的FeatureSelection,该方法可以获取所有图层的选择要素.IMap中的FeatureSelection可不是IFeatureSelectio ...

随机推荐

  1. 关于tensorflow里面的tf.contrib.rnn.BasicLSTMCell 中num_units参数问题

    这里的num_units参数并不是指这一层油多少个相互独立的时序lstm,而是lstm单元内部的几个门的参数,这几个门其实内部是一个神经网络,答案来自知乎: class TRNNConfig(obje ...

  2. 数据结构实验之链表四:有序链表的归并(SDUT 2119)

    #include <bits/stdc++.h> using namespace std; struct node { int data; struct node *next; }; st ...

  3. loj6519 魔力环

    解题思路 考虑顺时针旋转 \(i\) 步得到的结果,根据Burnside引理,有 \[ Ans=\frac{\sum\limits_{i=0}^{n-1}C(i)}{n} \] \(C(i)\) 为旋 ...

  4. 【sed】进阶

      sed的基本用法已能满足大多数需求,但当需要时,知道这些高级特效的存在及如何使用将提供莫大的帮助!   1. 多行命令         sed编辑器提供三个用于处理多行文本的特殊命令: N:将数据 ...

  5. DS博客作业07—查找

    1.本周学习总结 1.1思维导图 1.2学习体会 本章学习了顺序表.树表.哈希表的查找方式,学会计算各种查找方式下的ASL 树表部分的b树和平衡二叉树较为复杂,哈希表相对容易掌握 期末要复习的有点多, ...

  6. Exponentiation(求高精度幂)

    Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 175340   Accepted: 42341 ...

  7. 软件-绘图-AutoCAD:百科

    ylbtech-软件-绘图-AutoCAD:百科 AutoCAD(Autodesk Computer Aided Design)是Autodesk(欧特克)公司首次于1982年开发的自动计算机辅助设计 ...

  8. MACBOOK 破解wifi密码

    MACBOOK 破解wifi密码 Table of Contents 1. 安装homebrew 2. 安装aircrack-ng 3. 获取wifi网卡信息 4. 获取所有可识别的wifi信息 5. ...

  9. Android中代码优化

    两个基本准则: 1.不要做冗余的工作 2.尽量避免次数过多的内存分配操作 Handler和内部类的正确使用 正确使用Context 正确使用Java四种引用方式:软引用,弱引用,虚引用,强引用 避免创 ...

  10. bind绑定服务的生命周期

    bindService(service, conn, flags); * service :意图 * conn :activity和服务的连接通道 * flags : BIND_AUTO_CREATE ...