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

[b][size=medium][color=black]1、创建thirdSync Web工程[/color][/size][/b]

1.1、File-New在出现的菜单中选择“Web Project”,在打开的对话框中的“Project Name”输入框中输入工程名称“thirdSync”,点击“Finish”完成。

[b][size=medium][color=black]2、导入工程所需Jar包[/color][/size][/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、编写业务代码[/color][/size][/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、编写配置文件[/color][/size][/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、发布工程[/color][/size][/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、付费专栏及课程。

余额充值