1. 定义服务接口。

package com.huey.demo.ws;

import javax.jws.WebParam;
import javax.jws.WebService; @WebService
public interface HelloService { public String sayHello(@WebParam(name="who") String who); }

2. 实现服务接口。

package com.huey.demo.ws.impl;

import javax.jws.WebParam;
import javax.jws.WebService; import com.huey.demo.ws.HelloService; @WebService(name="helloService", endpointInterface="com.huey.demo.ws.HelloService")
public class HelloServiceImpl implements HelloService { public String sayHello(@WebParam(name="who") String who) {
String helloMsg = "Hello, " + who + "!";
return helloMsg;
} }

3. Spring 配置,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: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"> <jaxws:endpoint id="helloService"
implementor="com.huey.demo.ws.impl.HelloServiceImpl" address="/hello" /> </beans>

4. 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">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> <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>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-app>

5. 启动 Tomcat 运行 web 工程,在浏览器键入 http://localhost:8080/hellocxf/ws/hello?wsdl,验证服务是否发布成功(hellocxf 为工程名)。

<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://impl.ws.demo.huey.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:ns1="http://ws.demo.huey.com/" name="HelloServiceImplService" targetNamespace="http://impl.ws.demo.huey.com/">
<wsdl:import location="http://localhost:8080/hellocxf/ws/hello?wsdl=HelloService.wsdl" namespace="http://ws.demo.huey.com/"/>
<wsdl:binding name="HelloServiceImplServiceSoapBinding" type="ns1:HelloService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sayHello">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="sayHello">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayHelloResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloServiceImplService">
<wsdl:port binding="tns:HelloServiceImplServiceSoapBinding" name="helloServicePort">
<soap:address location="http://localhost:8080/hellocxf/ws/hello"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

CXF(2.7.10) - Writing a service with Spring的更多相关文章

  1. CXF(2.7.10) - RESTful Services, JSON Support

    在 CXF(2.7.10) - RESTful Services 介绍了 REST 风格的 WebService 服务,数据传输是基于 XML 格式的.如果要基于 JSON 格式传输数据,仅需要将注解 ...

  2. Apache CXF实战之四 构建RESTful Web Service

    Apache CXF实战之一 Hello World Web Service Apache CXF实战之二 集成Sping与Web容器 Apache CXF实战之三 传输Java对象 这篇文章介绍一下 ...

  3. CXF(2.7.10) - A simple JAX-WS service

    1. 下载 apache-cxf-x.x.x.zip,在工程导入依赖的 jar 包.也可以基于 Maven 构建工程. 2. 定义服务接口. package com.huey.demo.ws; imp ...

  4. [CareerCup] 10.1 Client-facing Service 面向客户服务器

    10.1 Imagine you are building some sort of service that will be called by up to 1000 client applicat ...

  5. 基于cxf开发restful风格的Web Service

    一.写在前面 webservice一些简单的其他用法和概念,就不在这里赘述了,相信大家都可以在网上查到,我也是一个新手,写这篇文章的目的一方面是想记录自己成长的历程,另一方面是因为学习这个的时候花了点 ...

  6. ArcGIS Server 10.1 错误 service failed to start,

    启动发布的地图服务时出现如下错误: ERROR: service failed to start, ServiceStarter thread timeout. 具体原因未知. Google中说了可能 ...

  7. MyEclipse 10 之下Web Service 的创建和实现

    (一)Web service服务端开发 1. 新建一个Web service project, 菜单New -> Web Service Project, 2. 新建一个 Java Bean, ...

  8. CXF(2.7.10) - WSDL2Java generated Client

    以调用 http://www.webxml.com.cn/ 提供的 IpAddressSearchWebService 服务为例. 1. 使用 wsdl2java 工具,根据 wsdl 生成 JAX- ...

  9. CXF(2.7.10) - RESTful Services

    1. 定义 JavaBean.注意 @XmlRootElement 注解,作用是将 JavaBean 映射成 XML 元素. package com.huey.demo.bean; import ja ...

随机推荐

  1. aspose.cell制作excel常见写法

    //设置Excel的基本格式信息 Workbook workbook = new Workbook(); Worksheet worksheet = workbook.Worksheets[]; St ...

  2. ASP.NET项目中引用全局dll

    在ASP.NET项目中,有些dll是全局dll,也就是说,没有放在单个项目的引用中.它们一般存放在如下目录C:\Windows\assembly中 这个时候,我们需要在单个项目中引用他们,应该如何做呢 ...

  3. Light oj 1214-Large Division (同余定理)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1214 题意很好懂,同余定理的运用,要是A数被B数整除,那么A%B等于0.而A很大,那我 ...

  4. POJ 3922A Simple Stone Game

    题目链接 A Sample Stone Game 题目大意:给定n,k,表示最初时有n个石头,两个人玩取石子游戏,第一个人第一次可以取1~n-1个石头,后面每个人最多可以拿走前面一个人拿走的个数的K倍 ...

  5. How Much Work Does it Take to be a Successful Mathematician?

    http://mathoverflow.net/questions/9799/how-much-work-does-it-take-to-be-a-successful-mathematician# ...

  6. GMT、UTC、PDT 时间是什么?Linux下如何调整时区

       今天碰到一个时区配置问题,如果服务器时区配置不对,很可能在使用date相关函数时会出现莫名其妙的错误,现将相关时区说明及LINUX下调整时区方法记录如下,以做备忘. GMT GMT 是 Gree ...

  7. cocos2d-x 手电筒效果

    转自:http://blog.csdn.net/xujiezhige/article/details/8448524# 常见的手电筒效果,可以通过CCRenderTexture来实现.主要是通过修改渲 ...

  8. iis下FastCGI 的常见Error错误

    用iis服务器+FastCGI配置的php环境会经常出现FastCGI Error的错误,像5 (0x80070005).2147467259(0x80004005).1413 (0x80070585 ...

  9. Web APP 随笔

    自Iphone和Android这两个牛逼的手机操作系统发布以来,在互联网界从此就多了一个新的名词-WebApp(意为基于WEB形式的应用程序,运行在高端的移动终端设备). 开发者们都知道在高端智能手机 ...

  10. android Camera 数据流程分析

    这篇文章主要针对其数据流程进行分析.Camera一般用于图像浏览.拍照和视频录制.这里先对图像浏览和拍照的数据流进行分析,后面再对视频电话部分进行分析. 1.针对HAL层对摄像头数据处理补充一下 Li ...