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. egret -纹理集的制作

    1. 理集的使用 :http://www.codeandweb.com/ 下载软件: TexturePackergithub: 相关工具:https://github.com/ping-chen/eg ...

  2. Apache Hive 存储方式、压缩格式

    简介: Apache hive 存储方式跟压缩格式! 1.Text File hive> create external table tab_textfile ( host string com ...

  3. asp.net cors solution

    I have a simple actionmethod, that returns some json. It runs on ajax.example.com. I need to access ...

  4. REST Client

    1.  为什么要使用REST Client 在实际企业开发过程中经常会有这样的需求: 1.我当前开发的这个系统是需要调用其他系统的接口,也就是我们需要频繁的测试接口,尝试不同的入参参数去查看返回结果, ...

  5. scala-学习 2

    列表操作 List() 或者是 Nil 空list scala> val a = List() a:List[Nothing] = List() print(a.length) a.length ...

  6. c#数和二叉树

    树(Tree)是 n(n≥0)个相同类型的数据元素的有限集合.树中的数据元素叫结点(Node).n=0 的树称为空树(Empty Tree):对于 n>0 的任意非空树 T 有: (1)有且仅有 ...

  7. 奇偶数判断2(if else+switch语句)

    public class 奇偶数判断2 { public static void main(String [] agrs){ float s = 17f; //定义浮点型数据s float h = s ...

  8. AtomEye的使用

    网易博客粗略地在转载的基础上对AtomEye补充了概述: AtomEye: Atomistic configuration viewer developed by J. Li. This progra ...

  9. keras—多层感知器MLP—IMDb情感分析

    import urllib.request import os import tarfile from keras.datasets import imdb from keras.preprocess ...

  10. impulse···········

    impulse - Bing dictionary US['ɪm.pʌls]UK['ɪmpʌls] n.冲动:冲量:推动力:刺激 v.推动 网络脉冲:冲击 变形Plural Form:impulses ...