Creating a Simple Web Service and Client with JAX-WS
Creating a Simple Web Service and Client with JAX-WS
发布服务
package cn.zno.service.impl; import javax.jws.WebService;
import javax.xml.ws.Endpoint; @WebService
public class HelloServiceImpl { public String say(String name) {
System.out.println(name);
return "invoked";
} public static void main(String[] args) {
Endpoint.publish("http://localhost:8080/HelloServic",new HelloServiceImpl());
} }
查看wsdl

http://localhost:8080/HelloServic?wsdl

生成客户端代码
cmd 运行 %JAVA_HOME%/bin/wsimport.exe 脚本
E:\>wsimport -keep http://localhost:8080/HelloServic?wsdl
parsing WSDL... Generating code... Compiling code... E:\>
目录
E:.
└─cn
└─zno
└─service
└─impl
HelloServiceImpl.class
HelloServiceImpl.java
HelloServiceImplService.class
HelloServiceImplService.java
ObjectFactory.class
ObjectFactory.java
package-info.class
package-info.java
Say.class
Say.java
SayResponse.class
SayResponse.java
创建客户端
import java.net.MalformedURLException;
import java.net.URL; import javax.xml.namespace.QName;
import javax.xml.ws.Service; import cn.zno.service.impl.HelloServiceImpl; public class Test {
public static void main(String[] args) throws MalformedURLException {
// String namespaceURI, String localPart
QName qname = new QName("http://impl.service.zno.cn/","HelloServiceImplService"); Service service = Service.create(new URL("http://localhost:8080/HelloServic?wsdl"),qname);
HelloServiceImpl serv = service.getPort(HelloServiceImpl.class);
String response = serv.say("hi");
System.out.println(response); } }
测试
启动服务器
运行客户端
1.服务器Console 打印:hi
2.客户端Console 打印:invoked
Creating a Simple Web Service and Client with JAX-WS的更多相关文章
- Creating A Simple Web Server With Golang
原文:https://tutorialedge.net/post/golang/creating-simple-web-server-with-golang/ -------------------- ...
- web service c# 互调 java (转)
一:简介 本文介绍了Java与.NET开发的Web Services相互调用的技术.本文包括两个部分,第一部分介绍了如何用.NET做客户端调用Java写的Web Services,第二部分介绍了如何用 ...
- C# Web Service 初级教学
原文连接:http://www.codeproject.com/cs/webservices/myservice.asp作者:Chris Maunder Introduction Creating y ...
- [转]Calling Web Service Functions Asynchronously from a Web Page 异步调用WebServices
本文转自:http://www.codeproject.com/Articles/70441/Calling-Web-Service-Functions-Asynchronously-from Ove ...
- Android开发之使用Web Service进行网络编程
使用Web Service进行网络编程 Android应用通常都是执行在手机平台上.手机系统的硬件资源是有限的,无论是存储能力还是计算能力都有限.在Android系统上开发.执行一些单用户.小型应用是 ...
- 在Web Service中傳送Dictionary
有個需求,想在Web Service中傳遞Dictionary<string, string>參數,例如: 排版顯示純文字 [WebMethod] public Dictionary< ...
- Web Service(下)
4.WSDL文档 <?xml version='1.0' encoding='UTF-8'?> <wsdl:definitions xmlns:xsd="http://ww ...
- 问题:不支持Dictionary;结果:在Web Service中傳送Dictionary
在Web Service中傳送Dictionary 有個需求,想在Web Service中傳遞Dictionary<string, string>參數,例如: 排版顯示純文字 [WebMe ...
- C++请求web service与xml解析
1. C++解析XML的开源库 在项目中XML的解析使用的是开源的第三方库,TinyXML:这个解析库的模型通过XML文件,然后再内存中生成DOM模型,从而让我们能够非常方便的遍历这颗XML树. DO ...
随机推荐
- SRC是在本位置显示:source的缩写,源的意思 HREF是点击后连接的目标:HyperlinkReference,超链接引用
SRC是在本位置显示:source的缩写,源的意思HREF是点击后连接的目标:HyperlinkReference,超链接引用
- Hibernate的一个问题object references an unsaved transient instance - save the transi5
1 我做了一对多和多对一的双向关联关系,在User这一方@ManyToOne已经设置了级联Cascade,这样在测试程序中保存User时,Group也应该自动保存,为什么会抛出以下的异常: (我是按着 ...
- 吴裕雄 实战PYTHON编程(5)
text = '中华'print(type(text))#<class 'str'>text1 = text.encode('gbk')print(type(text1))#<cla ...
- pyplot-常用图表
pyplot-常用图表 介绍最常用的:折线图.散点图.柱状图.直方图.饼图 的绘制 需要学习的不只是如何绘图,更是什么样的数据用什么图表显示效果最好 折线图 折线图用于显示随时间或有序类别的变化趋势 ...
- maven配置国内镜像库
https://www.cnblogs.com/xiongxx/p/6057558.html
- ionic2
拨打电话: <access origin="tel:*" launch-external="yes" /> 发邮件: <access orig ...
- mysql中树形结构表的操作
一种是:邻接表模型(局限性:对于层次结构中的每个级别,您需要一个自联接,并且随着连接的复杂性增加,每个级别的性能自然会降低.在纯SQL中使用邻接列表模型充其量是困难的.在能够看到类别的完整路径之前,我 ...
- svn: authentication cancelled
从svn 下程序时用户名和密码输入正确后报如图错误! 控制台输出: svn: authentication cancelled svn: authentication cancelled ...
- zoj1003-Max Sum (最大连续子序列之和)
http://acm.hdu.edu.cn/showproblem.php?pid=1003 Max Sum Time Limit: 2000/1000 MS (Java/Others) Mem ...
- 判断UNITY版本号
代码示例: #if (UNITY_5_3 || UNITY_5_4 || UNITY_5_5 || UNITY_5_6 || UNITY_5_7 || UNITY_5_8 || UNITY_5_9)u ...