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. ucGUI例程收藏

    ucGUI 几个重要例程Demo   按钮的定制 #include <stddef.h> #include <string.h> #include "WM.h&quo ...

  2. Ubuntu12.04 使用中遇到的问题

    这个随笔回记录使用Ubuntu遇到的一些问题   不定期进行整理和分类 1.Question:   ubuntu 无法检测包或者源码包 Description:Ubuntu软件中心打开时报错  无法检 ...

  3. code::blocks编译多文件 没有定义的引用

    code::blocks是一款据说灰常强大的IDE,以前虽然也经常使用,但一没用过高度功能,二来没用它写过工程性的东西,简单点说就是一个以上的源文件并且加入其他非标准的头文件,今天想做一个多文件的语法 ...

  4. Linq to SQL 绑定 ComboBox

    最近学习Linq to SQL,发现Linq是一个开发轻量数据库的好东西,大大简化了数据连接.查询过程.但是在绑定ComBoBox的时间发现了一个问题:Linq查询后得到的数据tolist后,只能实现 ...

  5. mysql数据库表间内外链接详解

    1. 内连接(自然连接) 2. 外连接 (1)左外连接 (左边的表不加限制)(2)右外连接(右边的表不加限制)(3)全外连接(左右两表都不加限制) 3. 自连接(同一张表内的连接) SQL的标准语法: ...

  6. 谈谈C#基元类型

    首先看一下.NET 中的基元类型,如下表: C# Type | .NET Framework Type -------------| ---------------------- bool | Sys ...

  7. [Angular 2] How To Debug An Angular 2 Application - Debugging via Augury or the Console

    In this lesson we will learn several ways to debug an Angular 2 application, including by using Augu ...

  8. [Jest] Track project code coverage with Jest

    Jest comes pre-packaged with the ability to track code coverage for the modules you're testing, but ...

  9. rtp的封包与拆包h264

    请看文档rfc3984 1.看h264的帧 SPS序列參数帧 00 00 00 01 67 64 . . .. PPS图像參数帧 00 00 00 01 68 EE... . I帧 00 00 00 ...

  10. 最简单的视频编码器:编译(libx264,libx265,libvpx)

    ===================================================== 最简单的视频编码器系列文章列表: 最简单的视频编码器:编译 最简单的视频编码器:基于libx ...