加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

基于CXF的webservice开发

发布时间:2020-12-16 23:09:30 所属栏目:安全 来源:网络整理
导读:1.webservice接口的发布。 ? (1)接口的定义 ? ? ? ? @WebServicepublic interface IWorkformReturnOperater {String HelloWorld(String name);} ? ?(2)实现类 @WebService(endpointInterface = "com.dvte.IWorkformReturnOperater",serviceName = "wsFor

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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读