Posted on 2012-10-17 14:36
谁用我名字啦? 阅读(156)
评论(0) 编辑 收藏 所属分类:
web service
开发工具:MyEclipse 8.6
开发步骤:
1.创建XFire的webservice项目
File->New->Web Service Project,弹出Web Service Project窗口,需要
填写Project Name(例子是Demo),选择XFire创建完成后,打开生成的web.xml文件,可以看到,XFire已经配置好了。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>XFireServlet</servlet-name>
<servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
2.创建WebService服务 选择Toolbars上的New Web Service,弹出New Web Service窗口,选择Strategy:Create web service from Java class(Bottom-up scenario)并勾选下面的Create new Java bean,然后Next>,在Web service name中填写MyService,在Java package栏点击New...弹出窗口中Name:中填com.demo.service,然后点Finish。
完成后,在与WebRoot同级路径的WebServices下生成了一个Service的配置services.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<name>MyService</name>
<serviceClass>com.demo.service.MyService</serviceClass>
<implementationClass>
com.demo.service.MyServiceImpl
</implementationClass>
<style>wrapped</style>
<use>literal</use>
<scope>application</scope>
</service></beans> 同时生成了接口和实现类。
package com.demo.service;
//Generated by MyEclipse
public interface MyService {
public String example(String message);
}
package com.demo.service;
//Generated by MyEclipse
public class MyServiceImpl implements MyService {
public String example(String message) {
return message;
}
} 3.服务端代码生成完毕。 测试服务端:1.前提:配置Tomcat服务器,并完成WebService服务端的部署,然后启动Tomcat。
2.选择Toolbars上的Launch SOAP Web Service Explorer,在Web Services Explorer(下称WSE窗口)窗口右上角选择WSDL Page,然后在右侧Open WSDL ,输入网址:
http://localhost:8080/Demo/services/MyService?wsdl
如果status窗口显示IWAB0381I http://localhost:8080/Demo/services/MyService?wsdl was successfully opened,说明运行成功。否则会提示error一类的信息。
3.在Operations表格中单击example,输入hello service,单击Go,在status窗口显示
out (string): hello service!