创建一个项目
添加如下代码
package jx; import javax.jws.WebService; @WebService public class ItemService implements ItemServiceAPI{ public String sayHello() { return "HelloWorld"; } }
package jx; import javax.jws.WebService; @WebService public interface ItemServiceAPI { public String sayHello(); }
以上是一个接口和一个实现类
下面写一个Main方法
package jx; import javax.xml.ws.Endpoint; public class Main { public static void main(String[] args) { ItemServiceAPI impl=new ItemService(); Endpoint.publish("http://192.168.0.119:8999/ItemService", impl); } }
接下来运行,然后访问浏览器:
http://192.168.0.119:8999/ItemService?wsdl
<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><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://jx/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://jx/" name="ItemServiceService"> <types> <xsd:schema> <xsd:import namespace="http://jx/" schemaLocation="http://192.168.0.119:8999/ItemService?xsd=1"></xsd:import> </xsd:schema> </types> <message name="sayHello"> <part name="parameters" element="tns:sayHello"></part> </message> <message name="sayHelloResponse"> <part name="parameters" element="tns:sayHelloResponse"></part> </message> <portType name="ItemService"> <operation name="sayHello"> <input wsam:Action="http://jx/ItemService/sayHelloRequest" message="tns:sayHello"></input> <output wsam:Action="http://jx/ItemService/sayHelloResponse" message="tns:sayHelloResponse"></output> </operation> </portType> <binding name="ItemServicePortBinding" type="tns:ItemService"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding> <operation name="sayHello"> <soap:operation soapAction=""></soap:operation> <input> <soap:body use="literal"></soap:body> </input> <output> <soap:body use="literal"></soap:body> </output> </operation> </binding> <service name="ItemServiceService"> <port name="ItemServicePort" binding="tns:ItemServicePortBinding"> <soap:address location="http://192.168.0.119:8999/ItemService"></soap:address> </port> </service> </definitions>
这时使用jdk自带工具生成客户端
wsimport -keep -s . http://192.168.0.119:8999/ItemService?wsdl
目录下出现一个jx文件夹,里面是生成的源码ItemService,ItemServiceService,ObjectFactory,package-info,SayHello,SayHelloResponse
新建另一个项目,把jx代码复制进去
创建Main方法
package root; import jx.ItemServiceService; public class Main { public static void main(String[] args) { ItemServiceService m=new ItemServiceService(); String stm=m.getItemServicePort().sayHello(); System.out.println(stm); } }
执行后,输出HelloWorld
ItemServiceService.java中涉及到地址硬编码的可以抽出,配置。
相关推荐
JAX-WS自学笔记 本人自学JAX-WS笔记和简单例子,文档标题结构如下: JAX-WS使用教程 1、JAX-WS概述 2、创建Web Service 2.1 从java开始 2.1.1 运行wsgen 2.1.2 生成的WSDL和XSD 2.1.3 目录结构 2.2 从WSDL...
JAX-WS 2.2 RI 所包含的JAR包集合,包含25个JAR包,列表如下: FastInoset.jar gmbal-api-only.jar ha-api.jar javax.annotation.jar javax.mail_1.4.jar jaxb-api.jar jaxb-impl.jar jaxb-xjc.jar jaxws-api...
如果基于一个JAX-WS进行WebService开发,有很多教程,但是具体怎么更自动地生成一些文件,实现客户端与服务端的交互,都讲得不大清楚,为了让大家更方便地部署,我将服务端、客户端文件的生成与部署全过程以及测试...
webService部署tomcat需要的jax-ws 的完整jar包
基于jax-ws 实现的web service client和server端的demo程序。 注:如果使用的是 myeclipse 时 server 部署到tomcat 启动的时候会报错 解决办法:找到myeclipse安装目录下的 plugins 目录里 查找 webservices-rt.jar,...
亲测可用,Jax-ws所需要的JAR包,拷贝到tomcat安装路径的lib里,实现了webservice发布到tomcat,赞!
MyEclipse8_0中使用 JAX-WS 部署 WebService 实例 - 外衣 - 博客频道 - CSDN_NET.mht
JAX-WS 2.2 RI 所包含的JAR包集合,包含25个JAR包,列表如下: FastInoset.jar gmbal-api-only.jar ha-api.jar javax.annotation.jar javax.mail_1.4.jar jaxb-api.jar jaxb-impl.jar jaxb-xjc.jar jaxws-api...
使用JAX-WS(JWS)发布WebService 使用myeclipse开发java的webservice的两种方式 方式一: (此方式只能作为调试,有以下bug:jdk1.6u17?以下编译器不支持以Endpoint.publish方式发布document方式的soap,必须在...
JAX-WS2.0 API
The Java API for XML Web Services (JAX-WS) is a Java programming language API for creating web services, particularly SOAP services. JAX-WS is one of the Java XML programming APIs. It's a part of the ...
Jax-WS的简单实例 Jax-WS的简单实例
rar中包含整个项目的源码和数据库生成脚本,采用jax-ws发布Web Service服务,支持java客户端和.Net客户端调用,数据库采用oracle10g,里面有创建数据库脚本文件createTable_Oracle10g.sql,由于Hibernate映射表中会...
JAX-WS Web service 开发初步
jax-ws webservice完整demo,包含所有jax-ws 2.2jar包。
JAX-WS方式开发和部署webservice应用,JAX-WS方式开发和部署webservice应用,JAX-WS方式开发和部署webservice应用,JAX-WS方式开发和部署webservice应用,JAX-WS方式开发和部署webservice应用
利用myeclipse创建的 jax-ws demo
jax-ws demo.分享一个从别处得到的helloworld demo
JAX-WS规范是一组XML web services的JAVA API