1. 开发工具
MyEclipse 8
2. 开发步骤
1) 新建WEB PROJECT
2) MyEclipse 增加 XFire 1.2 包
3) 配置XFire
web.xml
4) 创建服务类
MathService.java
5) 配置services.xml
6 部署到TOMCAT6
7 测试
8. 完成
9. 详细用法参考
[url]http://xfire.codehaus.org/User's+Guide[/url]
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]