Use xfire to done your web services
1. Sample
Service:
First config, xfire-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- URLs to WebService mapping. Requests are forwarded through Springs' DispatcherServlet -->
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/BankInterface">
</entry>
//映射到URL的KEY
</map>
</property>
</bean>
<!-- Declare a parent bean with all properties common to both services -->
<bean id="bank" class="org.codehaus.xfire.spring.remoting.XFireExporter">
<property name="serviceFactory">
<ref bean="xfire.serviceFactory"/>
</property>
<property name="xfire">
<ref bean="xfire"/>
</property>
<property name="serviceBean">
<ref bean="bankInterfaceService[j2] "/>
</property>
<property name="serviceClass">
<value>com.fch.fps.bs.bankinterface.BankInterface[j3] </value>
</property>
//映射SERVICE类
</bean>
</beans>
THEN,WEB.XML:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/com/fch/fps/bs/spring/applicationContext.xml
classpath:org/codehaus/xfire/spring/xfire.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>xfire</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>xfire</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
这样启动服务,写 http://localhost:7001/配置工程名/ws/BankInterface 就可以看到,加上 ?WSDL 就可解析为XML
假如SERVICE有1方法“public void register()”,需要被CLIENT调用.
2. CLIENT
Just need few word like this:
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
Service ser=new ObjectServiceFactory().
Create(BankInterfaceService.class);
//xfire-servlet.xml中的接口 serviceBean
BankInterfaceService bankser=( BankInterfaceService)
new xfireproxyFactory.create(ser,url);
//this url must be http://localhost:7001/配置工程名/ws/BankInterface
Ok,now “bankser” can do whatever u want
Bankser.register();