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. Navi.Soft31.阅读导航

    Navi.Soft31.核心类库 Navi.Soft31.WinForm框架 Navi.Soft31.WebMVC框架 Navi.Soft31.微信WinForm框架 Navi.Soft31.Mobi ...

  2. php 二维数组打乱顺序

    public function shuffle_assoc($list) { if (!is_array($list)) return $list; $keys = array_keys($list) ...

  3. Java设计模式(17)解释器模式(Interpreter模式)

    Interpreter定义:定义语言的文法,并且建立一个解释器来解释该语言中的句子. Interpreter似乎使用面不是很广,它描述了一个语言解释器是如何构成的,在实际应用中,我们可能很少去构造一个 ...

  4. Struts2技术详解

    1, 当Action设置了某个属性后,Struts将这些属性封装一个叫做Struts.valueStack的属性里.获取valueStack对象: ValueStack vs = (ValueStac ...

  5. JDBC删除数据库实例

    在本教程将演示如何在JDBC应用程序中删除一个指定的数据库. 在执行以下示例之前,请确保您已经准备好以下操作: 具有数据库管理员权限,以在给定模式中创建数据库. 要执行以下示例,需要用实际用户名和密码 ...

  6. e784. 监听对JList选择变动

    When the set of selected items is changed, either by the user or programmatically, a list selection ...

  7. C# 窗体间传值(使用委托与自定义事件)

    using System; using System.Drawing; using System.Windows.Forms; namespace 跨窗体调用控件 { public partial c ...

  8. pycharm环境下:同文件夹下文件(.py)之间的调用,出现红线问题

    只要将pycharm下打开项目后: 将你运行文件(.py)的项目设置为根目录,就不会出现红色线:

  9. DShow + OpenGL播放视屏

    #include <DShow.h> #pragma include_alias( "dxtrans.h", "qedit.h" ) #define ...

  10. 机器学习结果加ID插入数据库源码

    import org.apache.spark.mllib.evaluation.BinaryClassificationMetrics import org.apache.spark.mllib.l ...