XFire是新一代的Java Web服务引擎,XFire使得在JavaEE应用中发布Web服务变得轻而易举。和其他Web服务引擎相比,XFire的配置非常简单,可以非常容易地和其他众多系统集成!这个是以前自己学XFire的时候写的小Demo!
好!进入主题,首先加载Servlet处理Services请求:
web.xml
配置WebServices服务:
接下来时接口的实现方法:
最后就是Client的调用了:
由于是以前写的代码,有很多不规范的地方!见谅!
好!进入主题,首先加载Servlet处理Services请求:
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>
</web-app>
配置WebServices服务:
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<service xmlns="http://xfire.codehaus.org/config/1.0"
xmlns:s="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<name>softceo</name>
<namespace>www.softceo.com</namespace>
<serviceClass>soft.ceo.whilr.bean.IProcess</serviceClass>
<implementationClass>
soft.ceo.whilr.bean.Process
</implementationClass>
</service>
</beans>
接下来时接口的实现方法:
package soft.ceo.whilr.bean;
public class Process implements IProcess {
public String outString() {
return "你调用了小旋风的远程方法!";
}
}
最后就是Client的调用了:
package com.test.other;
import java.net.MalformedURLException;
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.apache.commons.httpclient/Credentials;
import soft.ceo.whilr.bean.IProcess;
/**
*
* @author softceo945
*
*/
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
Service srvcModel = new ObjectServiceFactory().create(IProcess.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
String helloWorldURL = "http://localhost:8088/TestServices/services/softceo";
IProcess process=null;
try {
process = (IProcess) factory.create(srvcModel, helloWorldURL);
} catch (MalformedURLException e) {
e.printStackTrace();
}
System.out.println(process.outString());
}
}
由于是以前写的代码,有很多不规范的地方!见谅!