当前位置:网站首页>webService接口编写并发布与webService接口的调用(二)
webService接口编写并发布与webService接口的调用(二)
2022-04-22 05:54:00 【陈君扬】
webService接口的调用的两种方法
1. 根据接口url生成客户端代码,再根据生成的代码调用接口服务
(1)使用eclipse在需要调用接口的项目目录里的src上右键,选择new,如图:

(2)点击next录入webService接口的url地址 http://localhost:8089/testservice?wsdl。如图:

(3)点击Finish按钮,自动生成客户端代码了,根据客户端设置的包路径查看代码,如图:

(4)创建一个调用接口示例,TestServiceClient类:
public static void main(String[] args) {
LoginProxy proxy = new LoginProxy();
try {
System.out.println("====="+proxy.loginPass("admin", "123"));
} catch (RemoteException e) {
e.printStackTrace();
}
}
2. 用原生的jdk调用接口服务示例:
public static void main(String[] args) throws Exception {
URL url = new URL("http://localhost:8089/testservice");
// 指定命名空间和服务名称
QName qName = new QName("http://webService.test.com", "testService");
Service service = Service.create(url, qName);
// 通过getPort方法返回指定接口
TestService myServer = service.getPort(new QName("http://webService.test.com",
"LoginPort"), TestService.class);
// 调用方法 获取返回值
String result = myServer.loginPass("admin", "123");
System.out.println(result);
}
注:调用webService接口时,可能需要用到几个jar包,如:axis.jar、axis-ant.jar、axis-schema.jar、commons-discovery-0.2.jar、commons-logging-1.0.4.jar、jaxrpc.jar、wsdl4-1.5.1.jar
版权声明
本文为[陈君扬]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_36216193/article/details/108647743
边栏推荐
猜你喜欢
随机推荐
Hangzhou rail transit supervision platform edge cloud won the award and set a new benchmark in the industry
Kyushu cloud was selected into China's top 500 Xinchuang in 2021
出海美利坚 不可忽视的未成年人法律红线
并发专题详解
SSH password free login
How can I know in the code whether it runs in JUnit environment?
The annual list of its intelligent service excellent enterprises was released, and Kyushu cloud won the "2021 top 10 of Xinchuang operation and maintenance"
Golang内存逃逸
数美科技CTO梁堃建议:技术+运营组合防控 “杀猪盘”
数美科技获得ISO/IEC 27701隐私信息管理体系国际认证
九州云Edge MEP作为典型产品入选《中国边缘云研究》报告
TensorFlow 实现web人脸登录系统
OpenSSL self signed CA certificate and issuing server / client certificate
ES6 modularization
Asynchronous programming & concurrent asyncio
厉害了!九州云边缘计算管理平台获国家权威认证
Evaluation of the first Avalon 1246-85t chassis with large computing power and low power consumption
数美科技六周年 | 致敬背后的你
路由传参数
Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: “/?k=“









