之前使用的都是MyEclipse6.0在做WEB服务,里面使用的是XFIRE框架搭建服务平台,后来因为XFIRE更名之后不再更新,导致在最新MyEclipse9.0中使用的是JAX搭建服务。
此文档就是教如何快速的使用9.0开发WEB服务。
<wbr><wbr><wbr><wbr><wbr><wbr>步骤一:创建Web Service Project</wbr></wbr></wbr></wbr></wbr></wbr>

<wbr><wbr><wbr>这里我们使用的框架是</wbr></wbr></wbr>JAX-WS。他是目前比较流行和成熟的服务框架。注意,这里虽然我们选择了JAX-WS框架,但是最让人气愤的是MyEclipse9.0跟本不会导入这个JAR包……汗,JDK里又不自带,只有自己导了,否则后面在运行服务时会报类找不到的错误。
在选中Java构建路径

右侧的菜单中选择“Add Library”

选择自带的JAR包,下一步

纳闷,都整合了怎么就不导进来呢……也忒懒了吧。
选中JAX-WS两个包。就导入成功了!
<wbr></wbr>
<wbr><wbr><wbr>步骤二:在工程里创建包和业务类</wbr></wbr></wbr>

<wbr><wbr><wbr>步骤三:创建</wbr></wbr></wbr>SERVICE

<wbr><wbr><wbr><wbr><wbr><wbr><wbr>注意工程的选择,框架选择还是JAX-WS,下面的创建模式是选择从JAVA类中创建,因为我们已经写好了自己的业务类。</wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr><wbr><wbr><wbr>选择当前服务的实现类,SOAP使用文档/包装类型,最后一部分是设置是否在工程里生成WSDL文件,可以不选。</wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>步骤四:启动服务并测试</wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr>这里省略发布并启动服务器的步骤……</wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr>如何知道我们自己服务的对应的路径是什么呢?<span style="word-wrap:normal; word-break:normal; line-height:22px; font-size:11pt; font-family:宋体">如图找到对应的</span><span lang="EN-US" style="word-wrap:normal; word-break:normal; line-height:22px; font-size:11pt; font-family:'Times new roman'">sun-jaxws.xml</span><span style="word-wrap:normal; word-break:normal; line-height:22px; font-size:11pt; font-family:宋体">文件?</span></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr><wbr><wbr><wbr>在创建服务的时候会自动生成一个业务类的代理类。</wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>而请求服务的路径和对应的业务都记录在该XML文件中。</wbr></wbr></wbr></wbr></wbr></wbr></wbr>

输入正确的地址后,就看见了此页面,呵呵,右面的链接很熟悉吧,呵呵,点进去看看。

这就是我们成功发布的服务地址。
点击右侧的web service 浏览窗口。
<wbr></wbr>

将出现这个窗体,如果第一次运行的时候可能不是WSDL视图。点击右上角的图标切换到WSDL视图,输入我们的地址就可以测试输入了。^______^
恭喜我们成功发布了属于自己的服务!
<wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>步骤五:写客户端调用服务</wbr></wbr></wbr></wbr></wbr></wbr></wbr>
我们可以创建一个Java工程来测试我们的服务。

在我们的工程中创建客户端。

URL中粘贴我们已发布好的WEB
SERVICE地址,并且选择对应类所在的包。就可以点下一步。

如果检测无误,这里就是空白的,否则会有错误信息!
当创建成功之后,观察我们的项目。

<wbr><wbr><wbr><wbr>在报下面会生成多个类,个数是根据你的业务类的方法的多少而变化的。具体作用可以查看文档。这里不再细讲!</wbr></wbr></wbr></wbr>
<wbr><wbr><wbr>创建一个测试类,当中包含主方法。</wbr></wbr></wbr>

执行该JAVA程序,输出结果。
成功访问服务!^_____,^
<wbr></wbr>
==================以上为访问自己的服务==================
下面我们将访问一个网络上由.NET发布的服务。因为服务是基于XML通信的原理,是跨平台的,这也是它强大的原因。
http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl
以这个手机号码查询的服务为例。
还在之前的Java工程中创建该服务客户端。

点击下一步校验

是警告,忽略它。点击完成。

生成代码时,忽略这个警告,提示我们使用了一个非标准的协议。
我们对比一下自己的服务和网络服务所产生的客户端的不同。

Test包为自己所写服务的客户端,testNet包下为网络服务的客户端。

仔细观察发现,WS.JAVA类继承自Service说明这个类是我们要找的服务类。

成功!
分享到:
相关推荐
在本文中,我们将深入探讨如何使用 MyEclipse9.0 开发 Web Service,这是一个流行的集成开发环境(IDE),尤其适用于Java EE应用。Web Service是一种基于XML的通信方式,允许不同平台的应用之间进行交互。在...
### 使用MyEclipse 9.0开发WebService #### 背景介绍 随着技术的发展,Web Service成为一种重要的分布式计算模型,它允许不同系统之间通过网络进行数据交换和服务调用。MyEclipse作为一款功能丰富的集成开发环境...
通过这个SSH整合的项目,我们可以学习到如何在MyEclipse 9.0环境中高效地开发和管理Java Web应用,同时也能深入理解SSH框架之间的协同工作原理。对于初学者,这是一个很好的实践平台,对于有经验的开发者,这则是一...
该项目使用了MyEclipse9.0作为集成开发环境(IDE),Mysql作为数据库管理系统,以及Struts2和Hibernate作为核心框架来处理业务逻辑和数据持久化。 【描述】中提到的几个关键点: 1. **MyEclipse9.0**:MyEclipse是...
- Myeclipse 插件:axis2-eclipse-codegen-plugin-1.6.0.zip 和 axis2-eclipse-service-plugin-1.6.0.zip,用于在Myeclipse中支持Axis2的开发功能。 - Tomcat 插件:axis2-1.6.0-war.zip,包含Axis2的WAR文件,用于...
8. **开发环境**:MyEclipse 9.0是一个集成开发环境,支持Struts和Hibernate的项目创建和调试。在MyEclipse中,可以方便地创建Web项目,导入Struts和Hibernate的库,以及配置相关框架。 以上是Struts和Hibernate...
- **MyEclipse 9.0**:一款广泛使用的Java集成开发环境。 - **Tomcat 6.0**:流行的Java应用程序服务器。 - **JDK 6**:Java开发工具包,用于编写Java应用程序。 - **axis2-eclipse-codegen-plugin-1.6.0.zip**:...
1. 开发环境:Myeclipse 9.0 2. Java JDK:1.7 3. 数据库:MySQL 5.0 4. 应用服务器:Tomcat 7.0 搭建步骤: 1. **创建项目**: 在Myeclipse中新建J2EE项目,项目名称为“ssh”。如果已有一个同名项目,新建时会...
4. MyEclipse 9.0(可选,作为IDE) 配置环境变量: - 设置JAVA_HOME指向JDK的安装路径 - 设置CATALINA_HOME指向Tomcat的安装路径 - 设置CXF_HOME指向Apache CXF的安装路径 - 将%JAVA_HOME%\bin和%JAVA_HOME%\jre\...
【基于JSP家庭理财系统】是一款使用MyEclipse开发工具,结合Tomcat 9.0应用服务器以及SSM(Spring、SpringMVC、MyBatis)框架构建的Web应用程序。这个系统旨在帮助用户管理和跟踪家庭财务,实现智能化的理财规划。 ...
使用IDE,如MyEclipse 9.0 M1,创建一个新的Java Web项目,命名为`S2SH_Demo_3`。 3. **添加SSH框架支持**: - **Struts2框架**:导入所需的Struts2相关jar包,例如`struts2-spring-plugin-2.2.1.jar`,这允许...
- **IDE**: MyEclipse 9.0 - **Java EE 版本**: 5.0 - **框架版本**: - Spring: 3.0,配置文件为`applicationContext.xml` - Hibernate: 3.3,配置文件为`hibernate.cfg.xml` - Struts: 2.1,配置文件为`struts....
- 确保使用的MyEclipse版本支持Flex4插件,例如MyEclipse8.5,但9.0可能不兼容。 - Tomcat的webapps目录下需要有相应的配置文件以支持Flex-BlazeDS通信。 8. **学习要求**: - 开发者应具备J2EE基础,熟悉三大...
Tomcat 8.0/9.0作为Web服务器;SQLyog/Navicat作为数据库管理工具;Eclipse/MyEclipse/Idea作为开发环境。 - **前端技术**:Ajax、Vue等,用于实现前后端分离的交互式页面。 #### 二、系统功能设计 ##### 2.1 管理...