java最简单的访问webservice接口
1.导入pom依赖
<dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> <version>3.2.0</version> </dependency>
2.编写测试接口
import com.alibaba.fastjson.JSONObject;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import javax.xml.namespace.QName;
import java.io.IOException;
public static void web2() { // logger.info("--------调用webservice接口begin-------"); // 创建动态客户端 JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); //对方的wsdl地址 Client client = dcf.createClient("http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl"); try { QName qName = new QName("http://WebXml.com.cn/", "qqCheckOnline"); //参数1,参数2,参数3......按顺序放就看可以 Object[] objects1 = client.invoke(qName, "qqCode:8698053"); String json = JSONObject.toJSONString(objects1[0]); System.out.println("返回数据:" + json); } catch (Exception e) { e.printStackTrace(); // logger.info("服务器断开连接,请稍后再试"); } // logger.info("--------调用webservice接口end-------"); }