MyEclipse6.5上基于JAX-WS开发Webservice
2010年04月21日
MyEclipse6.5上基于JAX-WS开发Webservice(中文示例)
及web service explorer不能显示的问题
先原创的一部分:
如果打开web service explorer时点击左边的按钮不显示结果,那是因为IE的问题,可以选择window->web browser->firefox来解决。
同时新建webservice时最好是用上面的快捷键,而不是从other中选,两种界面分别如下:
从快捷键中选
从other中选
引用
http://blog.csdn.net/foart/archive/2009/06/21/4287515.aspx
1. Introduction
This document will outline the process of developing a JAX-WS web service and deploying it using MyEclipse 6.5 to the internal MyEclipse Tomcat server. The web service used in this tutorial will be a very simple calculator service that provides add, subtract, multiply and divide operations to the caller.
MyEclipse also supports developing web services using the existing XFire framework from previous MyEclipse releases. For folks needing to develop and deploy WebSphere JAX-RPC or WebSphere JAX-WS web services, please take a look at our MyEclipse Blue Edition of the MyEclipse IDE.
Additional resources covering web service creation using JAX-RPC, JAX-WS or XFire are included in the Resources section of this document.
2. System Requirements
This tutorial was created with MyEclipse 6.5. If you are using another version of MyEclipse (possibly newer), most of these screens and instructions should still be very similar.
If you are using a newer version of MyEclipse and notice portions of this tutorial looking different than the screens you are seeing, please let us know and we will make sure to resolve any inconsistencies.
3.新建一个工程
开始我们新建一个Web Service Project工程File->New->Web Service Project(Optional Maven Support)
Note:A JAX-WS web service can also be generated in any existing Java EE 5 web project.
我们给这个工程取名为WebServiceProject.注意JAX-WS支持只在javaEE5或更高版本的工程中是可行的。如果你需要使用低版本的工程类型(java1.4或者1.3),那么只能使用XFire Web Service代替JAX-WS。
这里我们使用上面的JAX―WS。
4.创建服务类
服务类就是一个普通的java类,负责提供我们想要发布的执行方法。这里我们写一个简单的计算器类,实现几个典型的计算器应用方法,如加减乘除。
首先我们先建一个包,WebServiceProject->src->new->package,取名com.myeclipseide.ws
让后我们在这个包下建一个类,Calculator.java.
根据上面提到的,这个计算器类实现计算器的加减乘除算法,简单实现:
Java代码
package com.myeclipseide.ws;public class Calculator {
public int add(int a, int b) {
return (a + b);
}
public int subtract(int a, int b) {
return (a - b);
}
public int multiply(int a, int b) {
return (a * b);
}
public int divide(int a, int b) {
return (a / b);
}
}
可以看出,这个类中的方法是非常简单的,没有用到特殊的注释还有接口,父类之类的东西。
5.创建一个Web Service
在上面的工具条中点击新建Web Service
Note:如果没有的话可以File->New->others->Myeclipse->WebService->webService
点击之后出现的屏幕,在Strategy中选择Bottom-up scenario,因为我们已经建立好了Calculator类而且想根据它建立JAX-WS服务。
下面是创建的最后一个屏幕,你需要选择提供webService方法的javaBean,在我们这个例子中就是我们已经建立好的Calculator类。
填好之后,Myeclipse会自动帮我们填满其他的项,Select Generate WSDL in project and hit Finish.
点击完成之后,Myeclipse会自动生成CalculatorDelegate代理类,还有一些必须的JAX-WS描述符,而且会自动在服务器目录下的web.xml中配置WebService的一些mappings,方便将webService部署到服务器中。
到此web service已经建立好了,我们开始部署它然后进行测试。
6.部署和测试webService。
这里我们不使用用Myeclipse自带的tomcat服务器,使用自己应经在电脑中部署好的tomcat5.5。
在server面板中右击,选择configure
部署自己的tomcat注意选择jdk要跟项目中的相同。
现在要向工程中导入JAX-WS的jar包
在项目名称上右击->properties->Add Library->Myeclipse Libraries->最后面的两个。
点击完成,导入成功。
Note:Myeclipse自带的tomcat中有自带的这两个jar包,可以不用导入。
6.1部署
在部署好的tomcat服务器上右击选择Add Deployment
点击完成。
6.2测试
运行tomcat服务器,在工具栏中点击launch WebService Explorer
打开后,点击右上角的WSDL视图,可以看到下面的屏幕
在WSDL URL中填写路径:http://localhost:8888/WebServiceProject/CalculatorPort?WSDL
解释下路径组成:
http://localhost:8888/是服务器的路径,我的端口号是8888,可以根据自己的更改,一般都是8080。
/WebServiceProject = We know by default the Web Context-root that is used to deploy(部署) web projects matches the name of the projects. (因为我们没有为这个工程自定义我们的Web Context-root,所以他就是这个工程的名字)
/CalculatorPort = As we saw from the last screenshot in Section #5, when our JAX-WS web service was generated, it was bound using a servlet-mapping in the web.xml file to the /CalculatorPort path.
XML代码
JAX-WS endpoint - CalculatorService
CalculatorService
CalculatorService
com.sun.xml.ws.transport.http.servlet.WSServlet
1
CalculatorService
/CalculatorPort
?WSDL = This is a universal query string argument that can be added to the end of any web service which will tell the web service to return it’s full WSDL to the caller. In this case, the WSDL is returned to our Web Services Explorer tool which loads it up, and displays the web services exposed operations to us.
弄清楚之后,我们开始测试,比如我们选择add方法:
填写args,点击go,在status中就会显示结果。
结果是正确的。
7.创建Webservice Client
现在我们已经部署好Webservice,而且应经测试过了,那我们新建一个Webservice client,来调用Webservice提供的方法。
7.1新建一个java project,给他取个名字。比如我们叫它ClientofWebService
在工具条中点击new Web Service Client
然后按照以下步骤操作:
The last step of the web service client creation is to specify either a WSDL File or a WSDL URL for the wizard to retrieve the web service WSDL from. In our case we are using the URL and generate the client into the new package com.myeclipseide.ws.client:
http://localhost:8888/WebServiceProject/CalculatorPort?WSDL
点击Next直到完成。
可以看到在新建的java project ClientofWebService中,src文件夹下产生了许多的文件,根据名称我们大体可以了解其意思,可以打开看一下源代码,其实不难理解。比如 add文件,就是Calculator类中add方法的两个参数的get和set方法。其他类似。
我们在文件夹下见一个类test.java写一个main函数测试
Java代码
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
/* Create the service instance */
CalculatorService service = new CalculatorService();
CalculatorDelegate delegate = service.getCalculatorPort();
/* Using the web service, perform the 4 calculations */
System.out.println(”1. 3+7=” + delegate.add(3, 7));
System.out.println(”2. 12-2=” + delegate.subtract(12, 2));
System.out.println(”3. 9*9=” + delegate.multiply(9, 9));
System.out.println(”4. 40/2=” + delegate.divide(40, 2));
}
}
运行得到如下结果:
1. 3+7=10
2. 12-2=10
3. 9*9=81
4. 40/2=20
测试完成。
发表评论
-
堆栈的认知!
2012-01-20 10:15 521堆栈的认知! 2010年11月2 ... -
堆和栈的区别
2012-01-20 10:15 545堆和栈的区别 2010年10 ... -
VC串口通讯win32SDK版
2012-01-20 10:14 764VC串口通讯win32SDK版 2011年05月14日 ... -
Eclipse插件之Java代码分析工具: FindBugs
2012-01-20 10:14 678Eclipse插件之Java代码分析工具: FindBugs ... -
编译 boost
2012-01-20 10:14 544编译 boost 2011年05月17日 ... -
常用词汇解释
2012-01-19 15:15 768常用词汇解释 2011年02月10日 1*Android ... -
Linux下FrameBuffer直接写屏
2012-01-19 15:15 847Linux下FrameBuffer直接写屏 2011年09月 ... -
Grub4dos命令用法
2012-01-19 15:15 682Grub4dos命令用法 2010年06月01日 blo ... -
linux下nginx+php的安装与配置
2012-01-19 15:15 584linux下nginx+php的安装与 ... -
C段错误总结
2012-01-19 15:15 672C段错误总结 2012年01月07日 最近一段时间在li ... -
读写windows注册表
2012-01-17 05:02 1311读写windows注册表 2011年05月22日 Win ... -
VC编译器配置及编译选项
2012-01-17 05:02 446VC编译器配置及编译选 ... -
VC中的0XCCCCCCCC
2012-01-17 05:02 635VC中的0XCCCCCCCC 2011年10月23日 在 ... -
Windows系统的Regsvr32
2012-01-17 05:02 779Windows系统的Regsvr32 2011 ... -
VC 中用 IPicture 在窗口中显示图片文件
2012-01-17 05:02 983VC 中用 IPicture 在窗口中显示图片文件 2011 ... -
MyEclipse的javabean
2012-01-16 03:53 652MyEclipse的javabean 2010年11 ... -
MyEclipse使用Junit
2012-01-16 03:53 750MyEclipse使用Junit 2011年05月08日 ... -
myeclipse深度剖析
2012-01-16 03:53 905myeclipse深度剖析 2010年04月16日 工欲 ... -
MyEclipse7.0
2012-01-16 03:53 688MyEclipse7.0 2010年05月06日 ...
相关推荐
myeclipse6.5上基于JAX-WS开发Webservice(中文示例).doc
MyEclipse6_5上基于JAX-WS开发Webservice(中文示例)
MyEclipse6.5基于JAX-WS开发Webservice
MyEclipse8_0中使用 JAX-WS 部署 WebService 实例 - 外衣 - 博客频道 - CSDN_NET.mht
MyEclipse基于JAX-WS开发Webservice+WebserviceClient客户端调用.zip
NULL 博文链接:https://liuyunlong1229.iteye.com/blog/1678559
基于jax-ws 实现的web service client和server端的demo程序。 注:如果使用的是 myeclipse 时 server 部署到tomcat 启动的时候会报错 解决办法:找到myeclipse安装目录下的 plugins 目录里 查找 webservices-rt.jar,...
jax-ws-webservice开发 通过myeclipse进行 jax-ws的开发及其客户的编写
利用myeclipse创建的 jax-ws demo
如果基于一个JAX-WS进行WebService开发,有很多教程,但是具体怎么更自动地生成一些文件,实现客户端与服务端的交互,都讲得不大清楚,为了让大家更方便地部署,我将服务端、客户端文件的生成与部署全过程以及测试...
MyEclipse中开发webservice的入门教程,采用的是jax-ws框架。
使用Myeclipse-8.5开发基于JAX-WS的Web-service实例.docx
使用JAX-WS(JWS)发布WebService 使用myeclipse开发java的webservice的两种方式 方式一: (此方式只能作为调试,有以下bug:jdk1.6u17?以下编译器不支持以Endpoint.publish方式发布document方式的soap,必须在...
MyEclipse 6.5注册码 2008-9-8测试可用
网络上有很多myeclipse6.5的注册码不能使用,这个有效期2013-12-31
学习JAX-WSWebService开发相关文档及Myeclipse开发方法。