使用Java SE 6 创建独立 Web Services - 服务端
2011-07-29 16:12
337 查看
注意:JDK环境为1.6及以上
清单 1. 服务器代码
请注意清单 1 中粗体显示的代码。这称为 Annotation 或元数据,由 Java SE 5 中引入的 Web Services 元数据规范 (Web Services Metadata Specification) 所使用。开发人员在对类和方法应用 Annotation 之前定义类和方法,以向运行时引擎指明如何将类及其方法作为 Web Services 和 Web Services 操作来启用。Java SE 6 附带了这样一个引擎。
假设编译后的文件在 F:/src/com/SayHello.class
1.进入CMD命令台:
2.进入src目录: F:/src>
3.输入: wsgen -cp . -keep -s F:/ com.SayHello
4.在F:下会生成一个com/jaxws目录,里面有两个类 GetGreeting.java和GetGreetingResponse.java
清单 2. 发布代码
查看 WSDL
输入 URL,例如
完成!
清单 1. 服务器代码
package com; import Javax.jws.WebService; @WebService public class SayHello { private static final String SALUTATION = "Hello"; public String getGreeting(String name) { return SALUTATION + " " + name; } }
请注意清单 1 中粗体显示的代码。这称为 Annotation 或元数据,由 Java SE 5 中引入的 Web Services 元数据规范 (Web Services Metadata Specification) 所使用。开发人员在对类和方法应用 Annotation 之前定义类和方法,以向运行时引擎指明如何将类及其方法作为 Web Services 和 Web Services 操作来启用。Java SE 6 附带了这样一个引擎。
@WebServiceAnnotation 将
SayHello类标记为实现某个 Web Services ,从而产生可部署的 Web Services 。这个特定的 Annotation 是一个 WSDL 映射 Annotation,并将 Java 源代码与表示 Web Services 的 WSDL 元素相关联。(有关 Java SE 6 中的其他 Annotation 的更多信息,请参阅参考资料。)
假设编译后的文件在 F:/src/com/SayHello.class
1.进入CMD命令台:
2.进入src目录: F:/src>
3.输入: wsgen -cp . -keep -s F:/ com.SayHello
4.在F:下会生成一个com/jaxws目录,里面有两个类 GetGreeting.java和GetGreetingResponse.java
清单 2. 发布代码
package com; import Javax.xml.ws.Endpoint; public class RunService { public static void main(String[] args) { System.out.println("SayHello Web Service started."); Endpoint.publish("http://localhost:8080/wsServerExample", new SayHello()); } }
查看 WSDL
输入 URL,例如
http://localhost:8888/wsServerExample?wsdl
完成!
相关文章推荐
- 使用 Eclipse 和 Java SE 6 创建独立 Web Services 应用程序,第 1 部分: Web Services 服务端应用程序
- 使用 Eclipse 和 Java SE 6 创建独立 Web Services 应用程序,第 1 部分: Web Services 服务端应用程序
- 使用Java SE 6 创建独立 Web Services - 客户端
- 使用 Eclipse 和 Java SE 6 创建独立 Web Services 应用程序,第 2 部分: Web 服务客户端应用程序
- Delphi 7 中使用Indy创建独立的 Web Services/SOAP 服务器(四)
- Delphi 7 中使用Indy创建独立的 Web Services/SOAP 服务器(二)
- Delphi 7 中使用Indy创建独立的 Web Services/SOAP 服务器(一)
- Eclipse 和 Java SE 6 创建独立 Web Services 应用
- Eclipse 和 Java SE 6 创建独立 Web Services 应用 二
- Delphi 7 中使用Indy创建独立的 Web Services/SOAP 服务器(三)
- Windows中安装使用Virtualenv来创建独立Python环境
- Maven搭建webService (一) 创建服务端---使用main函数发布服务
- 使用PHP创建一个socket服务端
- MVC文件上传09-使用客户端jQuery-File-Upload插件和服务端Backload组件让每个用户有专属文件夹,并在其中创建分类子文件夹
- 使用CXF开发WebService程序的总结(二):创建webservice服务端
- 应用AXIS开始Web服务之旅(soap web services)——使用三种不同的语言访问创建的Web服务,分别是JAVA、VB、VC
- 在独立的环境中通过使用基于 Java 的配置创建和使用Spring 容器
- 使用VS 2010 Beta1创建一个独立的网络仿真器
- Windows中安装使用Virtualenv来创建独立Python环境
- 阿里云centos7.3下 python3.6 使用 virtualenv 创建独立的虚拟环境