0.新建一个项目取名wsserver. pom.xml 文件如下

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>sidonia</groupId><artifactId>wsserver</artifactId><version>0.0.1-SNAPSHOT</version><properties><cxf.version>3.1.4</cxf.version></properties><dependencies><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-frontend-jaxws</artifactId><version>${cxf.version}</version></dependency><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-transports-http</artifactId><version>${cxf.version}</version></dependency><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-frontend-jaxrs</artifactId><version>${cxf.version}</version></dependency><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-transports-http-jetty</artifactId><version>${cxf.version}</version></dependency></dependencies>
</project>

1.新建一个interface 取名 HelloWorld

package com.test.hello;import javax.jws.WebService;@WebService
public interface HelloWorld {public void sayHello();
}

2.新建一个实现类,取名HelloWorldImpl

package com.test.hello;import javax.jws.WebService;@WebService(endpointInterface="com.test.hello.HelloWorld",serviceName="HelloWorldWS")
public class HelloWorldImpl implements HelloWorld{public void sayHello() {System.out.println("hello world");}
}

3.新建一个包含main方法的ServerMain类

public class ServerMain {public static void main(String[] args) throws Exception {HelloWorld helloWorldImpl = new HelloWorldImpl();Endpoint.publish("http://localhost:1234/ws", helloWorldImpl);System.out.println("webservice 暴露成功");}
}

4.这时候访问上面这个地址,就可以看见下面这个xml

<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://hello.test.com/"xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http"name="HelloWorldWS" targetNamespace="http://hello.test.com/"><wsdl:types><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"xmlns:tns="http://hello.test.com/" elementFormDefault="unqualified"targetNamespace="http://hello.test.com/" version="1.0"><xs:element name="sayHello" type="tns:sayHello" /><xs:element name="sayHelloResponse" type="tns:sayHelloResponse" /><xs:complexType name="sayHello"><xs:sequence /></xs:complexType><xs:complexType name="sayHelloResponse"><xs:sequence /></xs:complexType></xs:schema></wsdl:types><wsdl:message name="sayHello"><wsdl:part element="tns:sayHello" name="parameters"></wsdl:part></wsdl:message><wsdl:message name="sayHelloResponse"><wsdl:part element="tns:sayHelloResponse" name="parameters"></wsdl:part></wsdl:message><wsdl:portType name="HelloWorld"><wsdl:operation name="sayHello"><wsdl:input message="tns:sayHello" name="sayHello"></wsdl:input><wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse"></wsdl:output></wsdl:operation></wsdl:portType><wsdl:binding name="HelloWorldWSSoapBinding" type="tns:HelloWorld"><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="HelloWorldWS"><wsdl:port binding="tns:HelloWorldWSSoapBinding" name="HelloWorldImplPort"><soap:address location="http://localhost:1234/ws" /></wsdl:port></wsdl:service>
</wsdl:definitions>

5.现在写客户端 取名wsclient

6.cmd 到D盘找个合适的地方 命令行执行 wsdl2java http://localhost:1234/ws?wsdl,这时候这里就会根据这个wsdl生成相应的类,把它考到客户端项目下面

7.新建一个ClientMain类

package com.test.hello;public class ClientMain {public static void main(String[] args) {HelloWorldWS factory = new HelloWorldWS(); //显然HelloWorldWS是一个工厂类HelloWorld helloWorld = factory.getHelloWorldImplPort();helloWorld.sayHello();}
}

一运行,服务器端控制台就会打印出hello world

转载于:https://www.cnblogs.com/heben/p/5391311.html

CXF学习(2) helloworld相关推荐

  1. jQuery学习笔记--Helloworld

    刚学习jQuery,觉得有的东西确实有必要写下来,加深下记忆,本文纯属给自己写的,希望大家不要见笑 jQuery是什么? jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多j ...

  2. (转)CXF学习笔记一:如何创建、发布和访问基于CXF的服务

    FROM:http://blog.csdn.net/yuvmen/archive/2009/11/09/4790805.aspx 主要参考http://cxf.apache.org的相关内容: 1.使 ...

  3. CXF学习(4) 处理无法自动转换的复合数据类型

    只贴出服务端代码 1.Service接口类 package com.test.hello;import java.util.Map;import javax.jws.WebService; impor ...

  4. Salesforce LWC学习(二) helloWorld程序在VSCode中的实现

    上一篇我们简单的描述了一下Salesforce DX的配置以及CLI的简单功能使用,此篇主要简单描述一下LWC如何实现helloWorld以及LWC开发时应该注意的一些规范. 做国内项目的同学直观的感 ...

  5. 1.ROS编程学习:helloworld的c++与python实现

    目录 一.c++实现 1.创建工作空间 3.CMakeLists.txt配置 4.catkin_make编译 5.source一下,配置环境变量 6.roscore+rosrun 二.python实现 ...

  6. nsi学习之HelloWorld

    nsis用于打包window环境安装.卸载程序,免费开源软件(不管你用于任何用途). window环境打包是做什么? 也许你见过有的程序,copy个文件夹(或者文件),点击扩展名是.exe的文件就可以 ...

  7. SpringMVC学习笔记——HelloWorld

    一.预备工作 创建Maven webapp工程. 使用Maven配置了需要使用的Jar包,Spring基于4.0.0版本. pom.xml如下: <project xmlns="htt ...

  8. 深度学习之Helloworld

    文章转载自:https://blog.csdn.net/gdmj77zzh/article/details/75674463 ①前言 一.传统机器学习的回顾 人工智能是一个非常大的概念,而机器学习只是 ...

  9. lua学习笔记-HelloWorld

    2019独角兽企业重金招聘Python工程师标准>>> 运行lua脚本,lua hello.lua/dofile("hello.lua") print(" ...

最新文章

  1. 持续集成-软件和库的统一
  2. KenBurns特效组件KenBurnsView
  3. 一个按键控制数码管的开和关_三菱PLC数码管显示及按键控制实验
  4. GridView 移除模板列
  5. word-break|overflow-wrap|word-wrap——CSS英文断句浅析
  6. ubuntu16.04安装PCL
  7. jar 工程我怎么在网页上url访问某一个方法_Java高级编程之URL处理
  8. Matlab的parfor并行编程
  9. 移动路由器刷linux,Linux小课堂开课了(7)-三线IP刷路由-移动-联通-电信
  10. 仿path首页滑动效果
  11. 前端怎么自我介绍_未雨绸缪,小米前端实习面经
  12. 记录小米fastboot刷机遇到的驱动问题
  13. 苹果笔记本电脑我的计算机在哪里设置密码,苹果笔记本忘记密码怎么办
  14. OneDrive免费5T云盘空间
  15. 爬虫实战---爬取猫眼电影
  16. 看不见的大猩猩--读书笔记
  17. Vue 2.0 真实点餐项目实战
  18. 月薪50K的测试工程师,要求原来是这样!
  19. 数据挖掘(一)频繁模式挖掘算法的实现和对比
  20. RTC使用野火例程,LSE复位可用,HSE和LSI不可用问题。

热门文章

  1. 【CSS】font样式简写(转)- 不是很建议简写
  2. VS2015配置freegult
  3. 设置 Linux 的 LD_LIBRARY_PATH 变量
  4. 文本处理工具AWK详解
  5. osg动态加载模型不显示_OSG仿真案例(8)——读取FBX格式文件并显示(无动画)...
  6. docker启动odoo提示module没有安装_Ubuntu20.04通过docker安装微信
  7. linux系统界面光标不见了---木有了
  8. docker安装问题
  9. 少儿编程100讲轻松学python(九)-python如何判断字符串是否为整数
  10. KPI到底是个啥东东,如何设置KPI,我想你需要懂这些