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. Spring Cloud / Spring Boot There was an unexpected error (type=Unauthorized, status=401). Full authentication is required to access this resource.

    访问EndPoint时会出现没有权限   There was an unexpected error (type=Unauthorized, status=401). Full authenticat ...

  2. ASK,OOK,FSK的联系和区别

    转自:http://www.cnblogs.com/zhihongyu/archive/2012/04/12/2443617.html ASK是幅移键控调制的简写,例如二进制的,把二进制符号0和1分别 ...

  3. 关于Unity的NGUI

    NGUI是严格遵循KISS原则并用C#编写的Unity(适用于专业版和免费版)插件,提供强大的UI系统和事件通知框架 KISS原则:Keep It Simple,Stupid NGUI实例 1.创建U ...

  4. Python之重复执行

    pip install retry 自动尝试5次,每次间隔2秒 from retry import retry @retry(tries=5, delay=2) def test(): print 1 ...

  5. VIM下的普通模式的相关知识

    什么为一次操作? 从进行插入模式开始,直到返回普通模式为止,在此期间的任何修改都视为一次操作:   使用 u 可以撤销最新的修改: 所以呢,控制好在插入模式的操作就可以控制好撤销命令的粒度: 另外,最 ...

  6. C++编程基础练习

    注:本文练习题均出自<Essential C++>第一章 练习1,1 从一个简单程序开始 #include<iostream> #include<string> u ...

  7. SpringBoot系列十一:SpringBoot整合Restful架构(使用 RestTemplate 模版实现 Rest 服务调用、Swagger 集成、动态修改日志级别)

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot整合Restful架构 2.背景 Spring 与 Restful 整合才是微架构的核心,虽然在整 ...

  8. Java如何格式化24小时格式的时间?

    在Java中,如何格式化24小时格式的时间?? 此示例使用SimpleDateFormat类的sdf.format(date)方法将时间格式化为24小时格式(00:00-24:00). package ...

  9. 嵌入式开发之hisilicon---hi3536 处理器简介

    (1)处理器概述 (2)处理器模块架构 --------------author:pkf -------------------time:7-19 -------------------------- ...

  10. C# 中 List.Sort运用(IComparer<T>)排序用法

    /// <summary> /// 比较人物类实例大小,实现接口IComparer /// </summary> public class InternetProtocolCo ...