<!-- Spring配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:org/codehaus/xfire/spring/xfire.xml, classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- XFire 配置 -->
<servlet>
<servlet-name>xfireServlet</servlet-name>
<servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>xfireServlet</servlet-name>
<!-- 在这个URI下开放Web Service服务 -->
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
</web-app>
<bean id="getHelloService" class="org.codehaus.xfire.spring.ServiceBean">
<property name="serviceBean" ref="helloService" />
<property name="serviceClass" value="sa.fs121.soap.service.IHelloService" />
<property name="inHandlers">
<list>
<ref bean="addressingHandler" />
</list>
</property>
</bean>
<bean id="addressingHandler" class="org.codehaus.xfire.addressing.AddressingInHandler" />
public String sayHello(String hello);
}
public String sayHello(String hello) {
System.out.println("接收客户端请求:" + hello);
return "Hello XFire, " + hello;
}
}
<bean id="testWebService" class="org.codehaus.xfire.spring.remoting.XFireClientFactoryBean">
<property name="serviceClass" value="sa.fs121.soap.service.IHelloService" />
<property name="wsdlDocumentUrl" value="http://localhost:8080/xfire/service/IHelloService?wsdl" />
</bean>
</beans>
ApplicationContext ctx = new ClassPathXmlApplicationContext("test.xml");
IHelloService hs = (IHelloService) ctx.getBean("testWebService");
System.out.println("服务器响应:" + hs.sayHello("hello, webservice"));
}