`
kaobian
  • 浏览: 208601 次
  • 性别: Icon_minigender_1
  • 来自: 哈尔滨
社区版块
存档分类
最新评论

xfire1.2.6 srping2.5 集成WebService

阅读更多
和大家分享一下我做的demo案例,xfire和spring2.5集成。
需要的jar文件
xfire-all-1.2.6.jar
jdom-1.0.jar
wsdl4j-1.6.1.jar
commons-codec-1.3.jar
commons-httpclient-3.0.jar
stax-api-1.0.1.jar
spring.jar
commons-logging-1.0.4.jar
spring-webmvc.jar
XmlSchema-1.1.jar

服务器端 接口类:
package iteye.kaobian;

public interface IHello {
	public String sayHello(String name);
}


接口实现类:
package iteye.kaobian;

public class SayHello implements IHello {
	public String sayHello(String name) {
		System.out.println("hello == " + name);
		return "hello " + name;
	}
}


spring文件配置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
	<!-- 引入XFire预配置信息 -->
	<import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
	
	<bean name="hello" class="iteye.kaobian.SayHello"/>
	
	<bean
		class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
		<property name="urlMap">
			<map>
				<entry key="/dataService.ws">
					<ref bean="dataService" />
				</entry>
			</map>
		</property>
	</bean>
	
	<!-- 使用XFire导出器 -->
	<bean id="baseWebService"
		class="org.codehaus.xfire.spring.remoting.XFireExporter"
		lazy-init="false" abstract="true">
		<property name="serviceFactory" ref="xfire.serviceFactory" />
		<property name="xfire" ref="xfire" />
	</bean>
	
	<bean id="dataService" parent="baseWebService" >
		<property name="serviceBean" ref="hello"/>
		<property name="serviceClass" value="iteye.kaobian.IHello" />
	</bean>

</beans>



web.xml文件配置:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

	 <context-param>       
	     <param-name>contextConfigLocation</param-name>    
	      <param-value>classpath*:applicationContext.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.codehaus.xfire.spring.XFireSpringServlet
		</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>xfire</servlet-name>
		<url-pattern>/WebService/*</url-pattern>
	</servlet-mapping>

	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
	
</web-app>



客户端调用WebService有两种方式,静态和动态,静态又分了很多种,我只讲一个和spring集成的:
代码:
package test;

import iteye.kaobian.IHello;

import org.codehaus.xfire.client.Client;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;


public class TestClient {

	IHello helloWorld = null;

	public static void main(String[] args) throws Exception {
		TestClient t = new TestClient();
		t.method2();
	}

	public void method1() throws Exception {
		String wsdl = "http://localhost:8080/Xfire/WebService/IHello?wsdl"; // 对应的WSDL文件
		Resource resource = new ClassPathResource(wsdl);
		Client client = new Client(resource.getInputStream(), null); // 根据WSDL创建客户实例
		Object[] objArray = new Object[1];
		objArray[0] = " iteye.kaobian ";
		Object[] results = client.invoke("sayHello", objArray);
		System.out.println(" result:  " + results[0]);
	}

	public void method2() throws Exception {

		ApplicationContext ctx = new ClassPathXmlApplicationContext("client.xml");
		IHello a = (IHello) ctx.getBean("testWebService");
		System.out.println(a.sayHello("fiugang"));
	}
}

客户端spring文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
	<bean id="testWebService"
		class="org.codehaus.xfire.spring.remoting.XFireClientFactoryBean">
		<property name="serviceClass">
			<value>com.bonc.IHello</value>
		</property>
		<property name="wsdlDocumentUrl">
			<value>
				http://localhost:8080/hesper/WebService/IHello?wsdl
			</value>
		</property>
	</bean>
</beans>


动态调用的客户端:
package test;
import java.net.URL;

import org.codehaus.xfire.client.Client;


public class DongTai {
	
	public static void main(String[] args)  throws Exception {
		Client client = new Client(new URL("http://localhost:8080/Xfire/WebService/IHello?wsdl"));    
        Object[] results = client.invoke("sayHello", new Object[] {"==========="});    
        System.out.println((String) results[0]);    
	}
}





1
0
分享到:
评论

相关推荐

    spring3.0整合Xfire1.2.6 开发webservice需要的jar包

    spring3.0整合Xfire1.2.6 开发webservice需要的jar包

    xfire-spring:xfire1.2.6+spring3.2.5webservice示例程序

    xfire-springxfire1.2.6+spring3.2.5webservice示例程序

    webservice中用到的jar,xfire-spring-1.2.6.jar

    webservice中用到的jar,xfire-spring-1.2.6.jar,xfire-spring-1.2.6.jar,xfire-spring-1.2.6.jar,xfire-spring-1.2.6.jar

    webservice xfire spring2.0完整实例

    webservice xfire1.2.6 spring2.0完整的代码,包含客户端两种方式(1 接口 2 url)

    xfire集成spring的jar包

    xfire集成了spring的jar包,放到工程中引用即可用xfire集成spring的方式进行webservice接口开发

    JQuery1.4.2+Struts2.1.8+JSON0.34+Spring2.5.6+Hibernate3.5+XFire1.2.6整合实例

    JQuery1.4.2+Struts2.1.8+JSON0.34+Spring2.5.6+Hibernate3.5+XFire1.2.6整合实例(已上传) 1、JSON0.34使用的是struts2附带的struts2-json-plugin-2.1.8.1.jar 2、db是mysql,名字为test,用户名root,密码空 3、...

    xfire-1.2.6

    activation.jar commons-logging.jar jdom-1.0.jar spring-mock.jar spring.jar stax-api-1.0.1.jar stax-utils-20040917.jar ...xfire-spring-1.2.6.jar xfire-xmlbeans-1.2.6.jar xstream-1.3.1.jar

    xfire-all-1.2.6.jar

    xfire-all-1.2.6.jar 开发webservice xfire 所需jar包

    重新编译打包的XmlSchema.1.1.1.jar和xfire-all1.2.6.jar

    为了解决spring整合cxf,xfire遇到的jar包冲突问题,将XmlSchema.1.1.1.jar和xfire-all1.2.6.jar修改后进行了重新编译打包

    xfire-1.2.6 jar包

    commons-httpclient-3.0.1.jar XmlSchema-1.1.jar commons-codec-1.3.jar xalan-2.7.0.jar wstx-asl-3.0.1.jar jdom-1.0.jar activation.jar spring-1.2.8.jar ...xfire-all-1.2.6.jar jsr173_1.0_api.jar

    xFire发布和调用WebService所用包少

    这个自己写的xFire发布WebService,包含发布和调用,可以用在企业中,而且所用的jar也比较少,不会出现...1.0.jar,spring-1.2.6.jar,wsdl4j-1.6.1.jar,xbean-spring-2.8.jar,xfire-all-1.2.6.jar,XmlSchema-1.1.jar]。

    xfire-1.2.6(含源码)

    XFire是新一代的Java Web服务引擎,XFire使得在JavaEE应用中发布Web服务变...和其他Web服务引擎相比,XFire的配置非常简单,可以非常容易地和Spring集成,它使得Java开发人员终于可以获得和.Net开发人员一样的开发效率

    xfire相关jar包

    进行WebService开发中所用到的xfire所有相关包如:xfire-jsr181-api-1.0-M1.jar、xfire-jaxws-1.2.6.jar、xfire-java5-1.2.6.jar、xfire-core-1.2.6.jar、xfire-annotations-1.2.6.jar、xfire-aegis-1.2.6.jar、...

    xfile核心jar包,兼容高版本spring

    Xfire框架使我们发布webservice变得非常简单,但是Xfile自从1.2.6版本之后就没有更新了,使得Xfile不能兼容高版本的spring框架。经本人不断调试终于解决了兼容性问题(亲测了spring3.x/spring4.x),有需要的小伙伴...

    xifre-1.2.6.rar

    使用xfire创建webservice是需要用的所有包,还有跟spring集成时(如果缺少)可能会报错的包,希望对大家有用

    xifre发布webService所用到的jar

    xfire-all-1.2.6.jar wsdl4j-1.5.1.jar spring-webmvc.jar spring-web.jar spring2.5.2.jar servlet-api.jar jdom.jar commons-logging1.0.4.jar

Global site tag (gtag.js) - Google Analytics