XFire 开发WebService

1. 开发工具
MyEclipse 8

2. 开发步骤
1) 新建WEB PROJECT
2) MyEclipse 增加 XFire 1.2 包
3) 配置XFire

web.xml

<?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>

<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>

</web-app>



4) 创建服务类
MathService.java


/**
*
*/
package cn.bisoft.java.webservice;

/**
* @author cs
*/
public class MathService
{
public int add(int a, int b)
{
return a + b;
}

}



5) 配置services.xml


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<name>MathService</name>
<namespace>http://w26.iteye.com/MathService</namespace>
<serviceClass>cn.bisoft.java.webservice.MathService</serviceClass>
</service>
</beans>



6 部署到TOMCAT6

7 测试

/**
*
*/
package cn.bisoft.java.webservice.client;

import java.net.URL;

import org.codehaus.xfire.client.Client;
import org.codehaus.xfire.test.AbstractXFireTest;
import org.jdom.Document;

/**
* @author cs
*/
public class MathServiceTest extends AbstractXFireTest
{

/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception
{

String url = "http://localhost:8080/xfire/services/MathService?wsdl" ;
Object[] params =new Object[]{1, 2} ;
Client client = new Client(new URL(url));
Object[] result = client.invoke("add", params);
System.out.println(result[0]);


}

public void testBeanService() throws Exception
{
Document response = invokeService("Test", "SOAPMessage.xml");

addNamespace("test", "urn:Test");
assertInvalid("//s:Fault", response);
assertValid("//test:Response", response);
assertValid("//test:Response[text()='howdy']", response);
}

}



8. 完成

9. 详细用法参考
[url]http://xfire.codehaus.org/User's+Guide[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值