1、编写WebService类,使用@WebService注解

package test;

import javax.jws.WebService;

@WebService
public class HelloServiceImpl{ public String say(String name) {
return "Hello "+name;
}
}

WebService类

2、使用main方法发布WebService

package test;

import javax.xml.ws.Endpoint;

public class Publisher {
public static void main(String[] args) {
Endpoint.publish("http://192.168.0.103:8088/hello", new HelloServiceImpl());
}
}

main方法发布WebService

3、发布成功后,访问发布地址+?wsdl获取网络服务描述语言,其中节点内tns冒号表示targetNameSpace,指向引用节点

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<!--
Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01.
-->
<!--
Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01.
-->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://test/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://test/" name="HelloServiceImplService">
<types>
<xsd:schema>
<xsd:import namespace="http://test/" schemaLocation="http://192.168.0.103:8088/hello?xsd=1"/>
</xsd:schema>
</types>
<message name="say">
<part name="parameters" element="tns:say"/>
</message>
<message name="sayResponse">
<part name="parameters" element="tns:sayResponse"/>
</message>
<portType name="HelloServiceImpl">
<operation name="say">
<input wsam:Action="http://test/HelloServiceImpl/sayRequest" message="tns:say"/>
<output wsam:Action="http://test/HelloServiceImpl/sayResponse" message="tns:sayResponse"/>
</operation>
</portType>
<binding name="HelloServiceImplPortBinding" type="tns:HelloServiceImpl">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="say">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="HelloServiceImplService">
<port name="HelloServiceImplPort" binding="tns:HelloServiceImplPortBinding">
<soap:address location="http://192.168.0.103:8088/hello"/>
</port>
</service>
</definitions>

WSDL

4、使用JDK中wsimport生成WebService客户端Java类

 wsimport -s . -p com.hjp.stub http://192.168.0.103:8088/hello?wsdl -Xnocompile

-s后面用点表示在当前目录下,-p后面第一个参数表示生成类的包,第二个参数是WebService服务的wsdl,-Xnocompile表示不需要编译,如果去掉-Xnocompile会有编译的class文件

5、将第四步生成好的Java文件,复制到客户端项目中,编写客户端测试代码

package com.hjp.client;

import com.hjp.stub.HelloServiceImpl;
import com.hjp.stub.HelloServiceImplService; public class Client { public static void main(String[] args){
//创建服务访问点集合对象
HelloServiceImplService helloServiceImplService=new HelloServiceImplService();
//获得服务点绑定的类
HelloServiceImpl helloService=helloServiceImplService.getHelloServiceImplPort();
//调用服务端方法
String returnstr=helloService.say("小明");
System.out.println(returnstr);
} }

客户端代码

6、扩展WebService内参数

如果想修改WSDL内节点名称,可以设置@WebService(在类上)、@WebMethod(在方法上)、@WebParam(在参数前)内name参数

如果排除其中某方法,使用@WebMethod内exclude=true

WebService之JDK中wsimport命令的更多相关文章

  1. webService开发(JDK版)

    最近做社保查询的东西,然而这个是三个公司一起做的,需要调其他公司的接口,他们公司用了webService这个当年比较流行的技术,于是乎就研究了一下这个webService. HTTP协议 + XML方 ...

  2. So easy Webservice 4.Java方式访问WebService(使用jdk1.6以上 wsimport命令)

    1.选中要调用的服务单击”服务说明” 2.获取wsdl文件.使用JDK1.6以上的版本的wsimport命令 a) 例如选中:http://webservice.webxml.com.cn/WebSe ...

  3. WEBSERVICE之JDK开发webservice

    转自:https://www.cnblogs.com/w-essay/p/7357262.html 一.开发工具与环境 1. jdk1.6版本以上(jdk1.6.0_21及以上版本) 2 .eclip ...

  4. (转) 使用jdk的xjc命令由schema文件生成相应的实体类

    背景:在webservice的开发过程中涉及到这一知识点,又必要来学习一下. 1 根据编写的schema来生成对应的java实体 1.1 实战 xcj命令有schema文件生成Java实体类 1.使用 ...

  5. JDK 中的证书生成和管理工具 keytool

    参考资料 该文中的内容来源于 Oracle 的官方文档 Java SE Tools Reference .Oracle 在 Java 方面的文档是非常完善的.对 Java 8 感兴趣的朋友,可以直接找 ...

  6. JDK中的设计模式

    Creational(创建模式) Abstract factory: 创建一组有关联的对象实例.这个模式在JDK中也是相当的常见,还有很多的framework例如Spring.我们很容易找到这样的实例 ...

  7. (转载)JDK中的设计模式

    写的很好,学习道路更轻松一些 原文地址:http://blog.csdn.net/gtuu0123/article/details/6114197 JDK中设计模式 分类: Java相关 设计模式 2 ...

  8. 使用jdk生成证书以及把证书导入到jdk中

    证书对于实现此单点登录非常之重要,证书是服务器端和客户端安全通信的凭证,本教程只是演示,所有用了JDK自带的证书生成工具keytool.当然在实际项目中你可以到专门的证书认证中心购买证书. 中文官方网 ...

  9. JVM基础系列第15讲:JDK性能监控命令

    查看虚拟机进程:jps 命令 jps 命令可以列出所有的 Java 进程.如果 jps 不加任何参数,可以列出 Java 程序的进程 ID 以及 Main 函数短名称,如下所示. $ jps 6540 ...

随机推荐

  1. 微信小程序——页面之间传递值

    小程序页面传值的方式: 1.正向传值:上一页面 -->  下一页面 url传值 本地储存 全局的app对象 2.反向传值:下一页面 -->  上一页面 本地储存 全局的app对象 先说一下 ...

  2. 关于很怂地退回SDK,ndk,gradle版本这件事。。。(降版本fix项目异常)

    前言:说明一下,这篇文章对别人应该是没什么用的,单作为自己的记录吧,方便以后查询 电脑重装后没有再使用之前的studio2.3,而是直接下载了最新版的v3.1.2,同时升级了所有SDK(28),NDK ...

  3. Data truncation: Out of range value for column 'Quality' at row 1

    Q: Data truncation: Out of range value for column 'Quality' at row 1 com.mysql.jdbc.MysqlDataTruncat ...

  4. SpringBoot系列二:搭建自己的第一个SpringBoot程序

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 一.根据官网手工搭建(http://projects.spring.io/spring-boot/#quick-start) 1 ...

  5. Zookeeper系统设计的优点

    转自:Zookeeper系统设计的优点.http://webcache.googleusercontent.com/search?q=cache:s6fr40t_5ncJ:www.chaozh.com ...

  6. TCP三次握手建立关系

    三次握手(three times handshake:three-way handshake)所谓的“三次握手”即对每次发送的数据量是怎样跟踪进行协商使数据段的 发送和接收同步,根据所接收到的数据量而 ...

  7. python模块之psutil详解

    一.psutil模块: 1.psutil是一个跨平台库(http://pythonhosted.org/psutil/)能够轻松实现获取系统运行的进程和系统利用率(包括CPU.内存.磁盘.网络等)信息 ...

  8. c#基础操作

    内网 IPAddress ipAddr = Dns.Resolve(Dns.GetHostName()).AddressList[];//获得当前IP地址 string ip = ipAddr.ToS ...

  9. SqlParameter 之 in

    List<string> ConditionList = new List<string>(); List<string> tempParameters = new ...

  10. Web APi之HttpClient注意事项以及建议

    Web APi之HttpClient注意事项以及建议 前言 之前对于用SelfHost来手动实现Web API的宿主模式,似乎不是太深入,所以本篇文章我们一起来讨论关于利用HttpClient来访问W ...