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. oracle rac 常见安装、管理错误

    1. 安装CRS失败,或执行root.sh报错,可能原因: (1) 节点间的时间不同步,解决方法:使用ntp服务 (2) Linux下启用了默认的防火墙,导致执行root.sh报错: Failure ...

  2. 吴裕雄 python神经网络 水果图片识别(2)

    import osimport numpy as npimport matplotlib.pyplot as pltfrom skimage import color,data,transform,i ...

  3. python复制文件,路径不存在问题(Windows和linux路径分隔符不统一)

    问题: python脚本涉及到复制文件,而我们需要兼容Windows.linux和mac环境 (Windows和linux的路径分隔符不同:通过os.path.sep查看分隔符)   如果用[路径名+ ...

  4. sql server profiler 的使用

    sql server profiler  是作为监听sql语句执行的软件, 主要是看NTUserName,system是系统的,看自己数据库的名字.

  5. java并发:AtomicInteger 以及CAS无锁算法【转载】

    1 AtomicInteger解析 众所周知,在多线程并发的情况下,对于成员变量,可能是线程不安全的: 一个很简单的例子,假设我存在两个线程,让一个整数自增1000次,那么最终的值应该是1000:但是 ...

  6. Android logcat输出中文乱码

    使用adb的logcat 命令查看系统日志缓冲区的内容,会发现在CMD的界面面,直接输出的中文内容是乱码. 这个问题出现在使用logcat将日志直接打印在当前的DOS窗口的时候会出现:使用logcat ...

  7. 10.Regular Expression Matching (String; Back-Track,DP)

    Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...

  8. fieldOfView

    fieldOfView 属性 fieldOfView:Number 语言版本:  ActionScript 3.0 运行时版本:  Flash Player 10, AIR 1.5 为三维视野指定一个 ...

  9. python数据类型内部结构解剖

    一.前言 我们知道,python是一种动态语言,可以将任何类型的数据赋给任何变量,譬如: # Python代码 x = 4 x = "four" 这里已经将 x 变量的内容由整型转 ...

  10. jquery源码学习-构造函数(2)

    最近几天一直在研究jquery源码,由于水平太低看得昏头转向.本来理解的也不是很深刻,下面就用自己的想法来说下jquery是如何定义构造函数初始化的.如果有什么不对的地方,希望个位高手指出.  一般写 ...