Web Service——xFire
1.新建一个web工程,需要导入的包有45个
2.在src里写接口和实现类
3.写配置文件WEB-INF中的
(1)web.xml
<?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">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:org/codehaus/xfire/spring/xfire.xml
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name>xfireServlet</servlet-name>
<servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>xfireServlet</servlet-name>
<!--这里可以改名,在用浏览器访问的时候在工程名后面输入services位置的值可以得到所有的WSDL,点击,地址栏得到服务器的WSDL-->
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
(2)配置applicationContext.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="helloExporters" class="org.codehaus.xfire.spring.remoting.XFireExporter">
<property name="serviceFactory" ref="xfire.serviceFactory"></property>
<property name="xfire" ref="xfire"></property>
<!--实现类的-->
<property name="serviceBean" ref="helloserviceImp"></property>
<!--接口的-->
<property name="serviceClass" value="com.bs.service.HelloService"></property>
<!--value可以改,输入上面web.xml时显示的WSDL前面的东西,应该只是一个名而已-->
<property name="name" value="firstHelloService"></property>
</bean>
<!--配置实现类-->
<bean id="helloserviceImp" class="com.bs.service.HelloServiceImp"></bean>
</beans>
4.建立客户端工程,一个web service project
5.建立客户端
new web service--->xfire--->WSDL URL:服务器成功的时候地址栏的那个XXXXXXX?wsdl--->Java package,建立一个包
--->finish.
工程会自动加载服务端和客户端,上面那个value+client里面的main方法会测试是否成功
1.新建一个web工程,需要导入的包有45个
2.在src里写接口和实现类
3.写配置文件WEB-INF中的
(1)web.xml
<?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">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:org/codehaus/xfire/spring/xfire.xml
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name>xfireServlet</servlet-name>
<servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>xfireServlet</servlet-name>
<!--这里可以改名,在用浏览器访问的时候在工程名后面输入services位置的值可以得到所有的WSDL,点击,地址栏得到服务器的WSDL-->
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
(2)配置applicationContext.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="helloExporters" class="org.codehaus.xfire.spring.remoting.XFireExporter">
<property name="serviceFactory" ref="xfire.serviceFactory"></property>
<property name="xfire" ref="xfire"></property>
<!--实现类的-->
<property name="serviceBean" ref="helloserviceImp"></property>
<!--接口的-->
<property name="serviceClass" value="com.bs.service.HelloService"></property>
<!--value可以改,输入上面web.xml时显示的WSDL前面的东西,应该只是一个名而已-->
<property name="name" value="firstHelloService"></property>
</bean>
<!--配置实现类-->
<bean id="helloserviceImp" class="com.bs.service.HelloServiceImp"></bean>
</beans>
4.建立客户端工程,一个web service project
5.建立客户端
new web service--->xfire--->WSDL URL:服务器成功的时候地址栏的那个XXXXXXX?wsdl--->Java package,建立一个包
--->finish.
工程会自动加载服务端和客户端,上面那个value+client里面的main方法会测试是否成功