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. JS escape、encodeURI 、encodeURIComponent 编码与解码[转]

    转至:http://jc-dreaming.iteye.com/blog/1702407 本文讨论如何对传递参数用JS编码与解码 1:编码与解码方法的对应关系 escape ------------- ...

  2. linux 查看当前所在目录的全路径

    有时候,使用linux的shell的时候需要查看当前位置的全路径,可以使用 pwd命令 当然,知道了该命令就可以通过man pwd来查看该命令的全部帮助手册.

  3. Spring容器-ApplicationContext的单例设计

    Spring容器-ApplicationContext的单例设计   每次通过new创建一个ApplicationContext容器,都会执行refresh方法,看源代码了解到这个refresh方法会 ...

  4. Android Activity切换动画overridePendingTransition

    Activity在切换或者是退出的时候能够使用渐入,滑动,缩放等动态效果.使用的就是方法overridePendingTransition,能够直在Activity其中直接调用. overridePe ...

  5. const 成员方法

    1.使用场景 代码提供者告诉客户(代码使用者),这个方法不会修改对象的内容,请客户放心使用. 2.代码提供者,尝试在const成员方法中修改对象内容,编译报错.在成员方法中,this是const 指针 ...

  6. mmc运输问题

    运输问题,有生产和需求平衡,不平衡, 实际模型,没有多大意义,只是变个符号而已. 下面的是平衡的,如果不平衡,约束变一下就可以了.

  7. iOS开发——网络编程Swift篇&(二)同/异&步请求

    同/异&步请求 同步: // MARK: - 同步请求 func httpSynchronousRequest() { //创建NSURL对象 var url:NSURL! = NSURL(s ...

  8. debian7安装oracle11g

    1,安装必须包 apt-get install gcc g++  make binutils libc6 libc6-dev libstdc++6 libstdc++5 rpm gawk alien ...

  9. iOS利用单例实现不同界面间的数据传输

    首先写一个单例类,继承NSObject check.h文件中 @property(strong ,nonatomic) UITable * Table; @property(strong ,nonit ...

  10. C语言结构体和联合体

    1.单链表插入 #include <stdio.h> #include <stdlib.h> #define FALSE 0 #define TRUE 1 typedef st ...