`
softlife
  • 浏览: 105837 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

cxf发布webservice示例

阅读更多
依赖jar文件:
axiom-api-1.2.7.jar
axis2-kernel-1.4.1.jar
jboss-backport-concurrent.jar
commons-httpclient-3.1.jar
commons-codec-1.3.jar
axiom-impl-1.2.7.jar

第一步:定义接口
package com.web.service;

import javax.jws.WebParam;
import javax.jws.WebService;

//@WebService(name = "TestService",targetNamespace = "http://service.web.com/")  
@WebService
public interface ITestService {
	//@WebMethod(action = "http://service.web.com/myService")  
	public String myService(@WebParam(name = "param")String param);

}

第二步:建立实现类
package com.web.service;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService(endpointInterface = "com.web.service.ITestService")
public class TestService implements ITestService {
	/**
	 * 测试webservice
	 */
	public String myService(@WebParam(name = "param")String param) {
		
		System.err.println(">>>>>>>>>>"+param+">>>>>>>>>>>>>>>>>>>>>test first webservice!!!");
		return param;
	}

}



第三步:进行webservice发布配置
<?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:jaxws="http://cxf.apache.org/jaxws"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
	http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
    <import resource="classpath:META-INF/cxf/cxf.xml" />
	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
	<bean id="aegisBean" class="org.apache.cxf.aegis.databinding.AegisDatabinding" />   

	<!-- 配置 WEB Service 开始-->
	<bean id="ITestService" class="com.web.service.TestService"/>
	<bean id="TestService_jaxWsServiceFactoryBean"  class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean">   
		<property name="wrapped" value="true" />   
		<property name="dataBinding" ref="aegisBean" />   
	</bean>   
	
	<jaxws:endpoint id="TestService" implementor="#ITestService" address="/TestService">   
		<jaxws:serviceFactory>   
			<ref bean="TestService_jaxWsServiceFactoryBean"/>   
		</jaxws:serviceFactory>   
	</jaxws:endpoint>  
	
	<!-- 配置 WEB Service 结束-->
</beans>

第三步:在项目web.xml中加入如下配置
 <!-- WEB SERVICE 配置开始 -->

	<servlet>
		<servlet-name>CXFServlet</servlet-name>
		<servlet-class>
			org.apache.cxf.transport.servlet.CXFServlet
		</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>CXFServlet</servlet-name>
		<url-pattern>/ws/*</url-pattern>
	</servlet-mapping>

  <!-- WEB SERVICE 配置结束 -->
分享到:
评论
1 楼 shaoping 2011-10-10  
有没有不带spring的纯cxf发布的webservie的实例啊?急求

相关推荐

Global site tag (gtag.js) - Google Analytics