Creating a Simple Web Service and Client with JAX-WS

发布服务

package cn.zno.service.impl;

import javax.jws.WebService;
import javax.xml.ws.Endpoint; @WebService
public class HelloServiceImpl { public String say(String name) {
System.out.println(name);
return "invoked";
} public static void main(String[] args) {
Endpoint.publish("http://localhost:8080/HelloServic",new HelloServiceImpl());
} }

查看wsdl

http://localhost:8080/HelloServic?wsdl

生成客户端代码

cmd 运行 %JAVA_HOME%/bin/wsimport.exe 脚本

E:\>wsimport -keep http://localhost:8080/HelloServic?wsdl
parsing WSDL... Generating code... Compiling code... E:\>

目录

E:.
└─cn
└─zno
└─service
└─impl
HelloServiceImpl.class
HelloServiceImpl.java
HelloServiceImplService.class
HelloServiceImplService.java
ObjectFactory.class
ObjectFactory.java
package-info.class
package-info.java
Say.class
Say.java
SayResponse.class
SayResponse.java

创建客户端

import java.net.MalformedURLException;
import java.net.URL; import javax.xml.namespace.QName;
import javax.xml.ws.Service; import cn.zno.service.impl.HelloServiceImpl; public class Test {
public static void main(String[] args) throws MalformedURLException {
// String namespaceURI, String localPart
QName qname = new QName("http://impl.service.zno.cn/","HelloServiceImplService"); Service service = Service.create(new URL("http://localhost:8080/HelloServic?wsdl"),qname);
HelloServiceImpl serv = service.getPort(HelloServiceImpl.class);
String response = serv.say("hi");
System.out.println(response); } }

测试

启动服务器

运行客户端

1.服务器Console 打印:hi

2.客户端Console 打印:invoked

Creating a Simple Web Service and Client with JAX-WS的更多相关文章

  1. Creating A Simple Web Server With Golang

    原文:https://tutorialedge.net/post/golang/creating-simple-web-server-with-golang/ -------------------- ...

  2. web service c# 互调 java (转)

    一:简介 本文介绍了Java与.NET开发的Web Services相互调用的技术.本文包括两个部分,第一部分介绍了如何用.NET做客户端调用Java写的Web Services,第二部分介绍了如何用 ...

  3. C# Web Service 初级教学

    原文连接:http://www.codeproject.com/cs/webservices/myservice.asp作者:Chris Maunder Introduction Creating y ...

  4. [转]Calling Web Service Functions Asynchronously from a Web Page 异步调用WebServices

    本文转自:http://www.codeproject.com/Articles/70441/Calling-Web-Service-Functions-Asynchronously-from Ove ...

  5. Android开发之使用Web Service进行网络编程

    使用Web Service进行网络编程 Android应用通常都是执行在手机平台上.手机系统的硬件资源是有限的,无论是存储能力还是计算能力都有限.在Android系统上开发.执行一些单用户.小型应用是 ...

  6. 在Web Service中傳送Dictionary

    有個需求,想在Web Service中傳遞Dictionary<string, string>參數,例如: 排版顯示純文字 [WebMethod] public Dictionary< ...

  7. Web Service(下)

    4.WSDL文档 <?xml version='1.0' encoding='UTF-8'?> <wsdl:definitions xmlns:xsd="http://ww ...

  8. 问题:不支持Dictionary;结果:在Web Service中傳送Dictionary

    在Web Service中傳送Dictionary 有個需求,想在Web Service中傳遞Dictionary<string, string>參數,例如: 排版顯示純文字 [WebMe ...

  9. C++请求web service与xml解析

    1. C++解析XML的开源库 在项目中XML的解析使用的是开源的第三方库,TinyXML:这个解析库的模型通过XML文件,然后再内存中生成DOM模型,从而让我们能够非常方便的遍历这颗XML树. DO ...

随机推荐

  1. TEXT 4 A question of standards

    TEXT 4 A question of standards 一个关乎标准的问题 Feb 9th 2006 From The Economist Global Agenda More suggesti ...

  2. iKcamp|基于Koa2搭建Node.js实战(含视频)☞ 记录日志

    沪江CCtalk视频地址:https://www.cctalk.com/v/15114923883523 log 日志中间件 最困难的事情就是认识自己. 在一个真实的项目中,开发只是整个投入的一小部分 ...

  3. JavaScript 累加求和练习 函数

    输入一个数,求从1加到这个数的和 主要代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" & ...

  4. BIGDECIMAL 四舍五入等取舍问题

    我输入的是1.35,但是电脑不可能取到整数,他的值如下:初始化数据:1.350000000000000088817841970012523233890533447265625ROUND_DOWN); ...

  5. php 利用迭代器遍历文件夹

    1.遍历文件夹 scandir 2.原生的迭代器Iterrate $scan_dir = "txtDir"; //下面会遍历txtDir 下面所有字文件夹中的文件哦 $dir_it ...

  6. 查询中mybatis的if判断里传入0

    1.传入的是long 或者 Integer类型 ,<if test="id != null "> 但是id传值为0时(前提是id对应的类型为long 或者 Intege ...

  7. IIS中的MIME类型设置

    https://www.cnblogs.com/David-Young/p/5323949.html

  8. tag-SMASS-1

    SMASS 是在vasp的DFTMD中决定着系综的类型,在手册中给出的该参数具体信息如下: SMASS = -3 | -2 | -1 | [real] ≥ 0 Default: SMASS = -3 ...

  9. 兼容谷歌、火狐、IE7.0以上浏览器div+css实现的带有蒙版的半透明弹窗效果[xyytit]

    整个页面变暗的蒙版效果,带有半透明边框的弹窗,用在网站里一定很酷. 最初见与奢饰品购物网站YMALL,后边研究了下,自己做了这个实例. 技术要点:css中几种透明样式的使用.不同的样式在不同的浏览器中 ...

  10. TZOJ 1840 Jack Straws(线段相交+并查集)

    描述 In the game of Jack Straws, a number of plastic or wooden "straws" are dumped on the ta ...