<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<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>/services</url-pattern>
</servlet-mapping>
public interface IXFireService {
public String sayHello(String name);
}
package cn.com.huixin.webservice.impl;
import cn.com.huixin.webservice.IXFireService;
public class XFireServiceImpl implements IXFireService {
public String sayHello(String name) { return name + " say: Hello!"; }
}
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://xfire.codehaus.org/config/1.0"> <service> <name>xfireService</name> <namespace> http://www.huixin.com.cn/webservice/helloworld </namespace> <serviceClass>cn.com.huixin.webservice.IXFireService</serviceClass> <implementationClass> cn.com.huixin.webservice.impl.XFireServiceImpl </implementationClass> </service> </beans>
package cn.com.huixin.webservice;
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;
public class XFireClient { public static void main(String[] args) { Service serviceModel = new ObjectServiceFactory().create(IXFireService.class);
XFire xfire = XFireFactory.newInstance().getXFire(); XFireProxyFactory factory = new XFireProxyFactory(xfire); String serviceUrl = "http://localhost:8080/webservice/services/xfireService"; IXFireService client = null; try { client = (IXFireService) factory.create(serviceModel, serviceUrl); } catch (Exception e) { System.out.println("Client call webservice has exception: " + e.toString()); }
String retvalue = client.sayHello("andrew Lau");
System.out.println(retvalue); }
}