1. 下载 apache-cxf-x.x.x.zip,在工程导入依赖的 jar 包。也可以基于 Maven 构建工程。

2. 定义服务接口。

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); }

3. 实现服务接口。

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;
} }

4. 发布服务。

package com.huey.demo.main;

import javax.xml.ws.Endpoint;

import com.huey.demo.ws.HelloService;
import com.huey.demo.ws.impl.HelloServiceImpl; public class Server { public void publishWebService() {
HelloService helloService = new HelloServiceImpl();
String address = "http://localhost:9090/hello";
Endpoint.publish(address, helloService);
} public static void main(String[] args) {
try {
new Server().publishWebService(); System.out.println("Server Ready...");
Thread.sleep(5 * 60 * 1000);
System.out.println("Server Existing...");
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("Ending...");
}
} }

5. 在浏览器键入 http://localhost:9090/hello?wsdl,验证服务是否发布成功。

<?xml version="1.0" encoding="UTF-8"?>
<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 namespace="http://ws.demo.huey.com/" location="http://localhost:9090/hello?wsdl=HelloService.wsdl"/>
<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 name="helloServicePort" binding="tns:HelloServiceImplServiceSoapBinding">
<soap:address location="http://localhost:9090/hello"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

6. 访问服务。

package com.huey.demo.main;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import com.huey.demo.ws.HelloService;

public class Client {

    public static void main(String[] args) {
try {
System.out.println("Starting Client..."); JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(HelloService.class);
factory.setAddress("http://localhost:9090/hello"); HelloService helloService = (HelloService) factory.create();
String helloMsg = helloService.sayHello("Huey");
System.out.println(helloMsg); } catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("Ending...");
}
} }

7. SoupUI 测试。

CXF(2.7.10) - A simple JAX-WS service的更多相关文章

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

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

  2. Create a simple REST web service with Python--转载

    今日尝试用python建立一个restful服务. 原文地址:http://www.dreamsyssoft.com/python-scripting-tutorial/create-simple-r ...

  3. CXF(2.7.10) - Writing a service with Spring

    1. 定义服务接口. package com.huey.demo.ws; import javax.jws.WebParam; import javax.jws.WebService; @WebSer ...

  4. CXF(2.7.10) - RESTful Services

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

  5. CXF(2.7.10) - WSDL2Java generated Client

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

  6. CXF实战之在Tomcat中公布Web Service(二)

    服务接口及实现类请參考WebService框架CXF实战(一) 创建Maven Web项目,在pom.xml中加入CXF和Spring Web的引用,因为CXFServlet须要Spring Web的 ...

  7. Win7 ArcGIS 10.5 安装错误 A service pack is required on this operatiing system

    前段时间有朋友反馈在Win7专业版下安装ArcGIS 10.5, 无法安装,弹出错误: A service pack is required on this operatiing system,如图: ...

  8. 转载 WebService 的CXF框架 WS方式Spring开发

    WebService 的CXF框架 WS方式Spring开发   1.建项目,导包. 1 <project xmlns="http://maven.apache.org/POM/4.0 ...

  9. WebService 的CXF框架 WS独立服务之HelloWorld

    WebService:不同系统不同语言的数据交互, CXF主要分为两种服务方式: 1 )JAX-WS:传输数据, xml格式,基于SOAP协议(规范:规定了xml传递数据的编码规范) ; 2 )JAX ...

随机推荐

  1. Spring 使用注解方式进行事物管理

    大家在使用spring的注解式事务管理时,对事务的传播行为和隔离级别可能有点不知所措,下边就详细的介绍下以备方便查阅. 事物注解方式: @Transactional 当标于类前时, 标示类中所有方法都 ...

  2. Spring Data JPA教程, 第八部分:Adding Functionality to a Repository (未翻译)

    The previous part of my tutorial described how you can paginate query results with Spring Data JPA. ...

  3. 浅析网站开发中的 meta 标签的作用

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  4. 剑指OFFER之用两个栈实现队列(九度OJ1512)

    题目描述: 用两个栈来实现一个队列,完成队列的Push和Pop操作.队列中的元素为int类型. 输入: 每个输入文件包含一个测试样例.对于每个测试样例,第一行输入一个n(1<=n<=100 ...

  5. PostgreSQL的 initdb 源代码分析之七

    继续分析:由于我使用initdb的时候,没有指定 locale,所以会使用OS的缺省locale,这里是 en_US.UTF-8 printf(_("The files belonging ...

  6. tomcat启动很慢的原因

    启动后tomcat显示的代码如下: 2014-4-3 10:50:15 org.apache.catalina.core.AprLifecycleListener init 信息: The APR b ...

  7. jsp页面用el表达式获取枚举的code

    jsp页面用el表达式获取枚举的code <c:set var="D_BUSINESS" value="<%=DeptEnum.D_BUSINESS%> ...

  8. PS-常用操作

    快捷键 设置图片的大小:ctrl+t 放大缩小:ctrl+空格+“+or-”

  9. Codeforces Round #331 (Div. 2) E. Wilbur and Strings dfs乱搞

    E. Wilbur and Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596 ...

  10. delphi queryCommandState

    如何 获取当前光标所在的字符属性 关键点 function queryCommandState(const cmdID: WideString): WordBool; safecall; 粗体 斜体 ...