[] Xfire+JDK1.5_0.6+Myeclipse+Tomcat6构建Webservice服务

[b][size=medium][color=black]1、创建thirdsync web工程[/size][/color][/b]

1.1、file-new在出现的菜单中选择“web project”,在打开的对话框中的“project name”输入框中输入工程名称“thirdsync”,点击“finish”完成。

[b][size=medium][color=black]2、导入工程所需jar包[/size][/color][/b]

2.1、service所需jar

xfire-all-1.2.6.jar
xfire-jsr181-api-1.0-m1.jar
spring.jar
xbean-spring-2.8.jar
jdom.jar
activation.jar

2.2、client所需jar

commons-httpclient-3.0.jar
commons-codec-1.3.jar
stax-api-1.0.1.jar
stax-utils-20040917.jar
wstx-asl-3.2.0.jar

2.3、junit4所需jar

junit.jar

[b][size=medium][color=black]3、编写业务代码[/size][/color][/b]

源代码如下所示:

[color=red]webservice接口[/color]
package com.webservice;public interface ithirdpartyservice {	   public int test(int a ,int b);}

[color=red]webservice接口实现类[/color]
package com.webservice;public class thirdpartyservice implements ithirdpartyservice {		/**	 * xfire测试用例	 */	public int test(int a, int b) {	    return a + b;	}}

[color=red]junit测试用例[/color]
package com.test;import java.net.malformedurlexception;import org.codehaus.xfire.xfire;import org.codehaus.xfire.xfirefactory;import org.codehaus.xfire.client.xfireproxyfactory;import org.codehaus.xfire.service.service;import org.codehaus.xfire.service.binding.objectservicefactory;import org.junit.ignore;import org.junit.test;import com.webservice.ithirdpartyservice;public class testthirdpartyservice {   //	@ignore	@test	// xfire测试用例	public void test() {		ithirdpartyservice client = null;		try {			service servicemodel = new objectservicefactory()					.create(ithirdpartyservice.class);			xfire xfire = xfirefactory.newinstance().getxfire();			xfireproxyfactory factory = new xfireproxyfactory(xfire);			string serviceurl = "http://192.168.0.156/thirdsync/service/thirdpartyservice";			client = (ithirdpartyservice) factory.create(servicemodel,					serviceurl);			system.out.println("返回值是" + client.test(12, 12));		} catch (malformedurlexception e) {			e.printstacktrace();		}	}}

[b][size=medium][color=black]4、编写配置文件[/size][/color][/b]

4.1、services.xml

在classes目录(即:src目录)下建立meta-inf\xfire目录,在该目录下建立services.xml文件。

[color=red]services.xml文件内容如下:[/color]
<?xml version="1.0" encoding="utf-8"?><beans>  	<service xmlns="http://xfire.codehaus.org/config/1.0"> 		<name>thirdpartyservice</name>  		<namespace>http://thirdsync/webservice/testservice</namespace>		<serviceclass>com.webservice.ithirdpartyservice</serviceclass>  		<implementationclass>com.webservice.thirdpartyservice</implementationclass>        </service>  </beans>  


4.2、web.xml

[color=red]web.xml文件内容如下:[/color]
<?xml version="1.0" encoding="utf-8"?><web-app version="2.4" 	xmlns="http://java.sun.com/xml/ns/j2ee" 	xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" 	xsi:schemalocation="http://java.sun.com/xml/ns/j2ee 	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">      <servlet>      <servlet-name>xfireservlet</servlet-name>      <servlet-class>           org.codehaus.xfire.transport.http.xfireconfigurableservlet      </servlet-class>  </servlet>    <servlet-mapping>      <servlet-name>xfireservlet</servlet-name>      <url-pattern>/servlet/xfireservlet/*</url-pattern>  </servlet-mapping>  <servlet-mapping>      <servlet-name>xfireservlet</servlet-name>      <url-pattern>/service/*</url-pattern>  </servlet-mapping>  <welcome-file-list>    <welcome-file>index.jsp</welcome-file>  </welcome-file-list></web-app>

[b][size=medium][color=black]5、发布工程[/size][/color][/b]

5.1、发布工程

这个很简单,我就不必说了吧。

[color=red]注意:我机器的tomcat的端口为80,ip:192.168.0.156,那么访问地址就是http://192.168.0.156/thirdsync/service/thirdpartyservice?wsdl,如果可以正常显示发布文件,则证明webservice发布成功。[/color]

[color=blue]小弟初次发帖,不足之处敬请包涵,请朋友多提意见,我的邮箱:yun0425@126.com,如有需要请联系我。[/color]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值