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. spring cloud 服务提供者

    1. pom 依赖: <parent> <groupId>org.springframework.boot</groupId> <artifactId> ...

  2. 使用css技术代替传统的frame技术

    http://www.dynamicdrive.com/style/layouts/item/css-left-frame-layout/ <!--Force IE6 into quirks m ...

  3. mysql 列转行

    第一种方法:使用序列化表的方法实现列转行 第一种方法:使用UNION的方法实现列转行 第二种方法:使用序列化表的方法实现列转行

  4. 格式与布局 float 左右悬浮边框

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. Ansible 书写我的playbook

    mysql 创建数据库 - hosts: localhost  remote_user: root  tasks: - name: test mysql    mysql_db:      name: ...

  6. Mysql update 一个表中自己的数据

    update  table ucf, table t2 set ucf.pcid = t2.pcid where t2.name = 'liming' and t2.gid= ucf.gid and ...

  7. Eclipse中Git插件使用技巧:还原文件

    如果修改了某个文件并未提交至本地库(add index),那么怎么还原呢?Git插件中并不像Svn插件直接提供有还原方式.其实无论是否提交至本地库或者远程库,还原操作的本质都是将文件的当前版本还原至之 ...

  8. 可能空字符串转换为浮点型或者整数型:java.lang.NumberFormatException: For input string: " "

    Integer.valueOf(str.equals("")?"0":str)

  9. Resume (Curriculum Vitae)

    The resume (Curriculum Vitae) is a selling tool outlining your skills and experience so an employer ...

  10. MyBatis高级查询

    -------------------------siwuxie095 MyBatis 高级查询 1.MyBatis 作为一个 ORM 框架,也对 SQL 的高级查询做了支持, MyBatis 高级查 ...