- 引入解析 Webservice服務的 jar包。 下面給出pom座標
<!-- 解析WebService JAR包 CXF -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>3.2.4</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>3.2.4</version>
</dependency>
- 創建 Webservice Client
public static String callWebSV(String wsdUrl, String operationName, String... params) throws Exception {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(wsdUrl);
//client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME, PASS_WORD));
Object[] objects;
// invoke("方法名",參數1,參數2,參數3....);
objects = client.invoke(operationName, params);
return objects[0].toString();
}
- controller 調用
@GetMapping(path = "websv")
public String websv() {
System.out.println("GetIn");
String webUrl = "http://192.168.20.10:8080/dataexchange/ws/query/attachment?wsdl";
String methodName = "run";
System.out.println("Calling" + webUrl);
toWebSV.callWebSV(webUrl, methodName, "A_BW0061_1542604227318");
System.out.println("Called");
return "Finished!Looking for console!";
}
結束。
如果有什麼建議,歡迎留言。