首先需要引入依赖jar包
#版本只供参考,具体看项目 <dependency> <grouId>org.apache.cxf</grouId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>3.1.6</version> </dependency> <dependency> <grouId>org.apache.cxf</grouId> <artifactId>cxf-rt-transports-http</artifactId> <version>3.1.6</version> </dependency>
JaxWsDynamicClientFactory
简介:只要指定服务器端wsdl文件的位置,然后指定要调用的方法和方法的参数即可,不关心服务端的实现方式。
public class Client3 { public static void main(String[] args) throws Exception { //方法名 String method = "sayHello" //参数 String param = "KEVIN" //实例化JaxWsDynamicClientFactory JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance(); //通过wsdl路径生成客户端实体 Client client = clientFactory.createClient("http://localhost:9090/helloWorldService?wsdl"); //调用方法传参 Object[] result = client.invoke(method, param); //打印回值 System.out.println(result[0]); } }
参考:https://www.cnblogs.com/langtianya/p/4939098.html