微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

基于CXF的webservice开发

1.webservice接口的发布。

  (1)接口的定义

       

@WebService
public interface IWorkformReturnoperater {

	String HelloWorld(String name);
}

   (2)实现类

@WebService(endpointInterface = "com.dvte.IWorkformReturnoperater",serviceName = "wsForForm")
public interface WorkformReturnoperater implements <span style="font-family: Arial,Helvetica,sans-serif;"></span><pre name="code" class="java">IWorkformReturnoperater
{String HelloWorld(String name){

 
      return "客户端你好:"+name;
}
}

 (3) ws-config.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:jaxws="http://cxf.apache.org/jaxws" xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:cxf="http://cxf.apache.org/core"
	xsi:schemaLocation="http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-aop.xsd "
	default-autowire="byType" default-lazy-init="true">
	<description>基于Apache CXF的Web Service配置文件</description>

	<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" />

	<!--  CXF webservice 配置  -->
	<jaxws:endpoint id="helloWord" implementor="com.dvte.<span style="font-family: Arial,sans-serif;">WorkformReturnoperater </span><span style="font-family: Arial,sans-serif;">"</span>
		address="/helloWord" />
</beans>
(4)在web.xml加入以下配置
        <context-param>
<span style="white-space:pre">		</span><param-name>contextConfigLocation</param-name>
<span style="white-space:pre">		</span><param-value>classpath*:/ws-config.xml</param-value>
<span style="white-space:pre">	</span></context-param>
        <listener>
<span style="white-space:pre">		</span><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
<span style="white-space:pre">	</span></listener>
         <!-- CXF 配置 -->
<span style="white-space:pre">	</span><servlet>
<span style="white-space:pre">		</span><servlet-name>CXFServlet</servlet-name>
<span style="white-space:pre">		</span><servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<span style="white-space:pre">	</span></servlet>
<span style="white-space:pre">	</span><servlet-mapping>
<span style="white-space:pre">		</span><servlet-name>CXFServlet</servlet-name>
<span style="white-space:pre">		</span><url-pattern>/wsservice/*</url-pattern>
<span style="white-space:pre">	</span></servlet-mapping>
 
(5)启动服务器,通过项目名/<span style="font-family: Arial,sans-serif;">wsservice/helloword ?wsdl来访问,如果看到xml文件那么就发布成功了</span>
   
2.客户端如何将wsdl.xml文件转为对应的java类
  (1)使用Eclipse创建一个webservice客户端,指定其wsdl.xml文件路径,点击完成,即可转化为我们熟悉的java类生成的类很多,只关心其接口即可。
  (2)使用<span style="font-family: Arial,sans-serif;">WSDL2Java工具类 来转换。具体的工具在我的资源里面下载</span>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐