创建JWS项目步骤:

1:创建接口

2:创建实现类

3:开启服务

1:编写接口

@WebService
public interface IMyService { public int add(int a,int b); public int minus(int a,int b);
}

  

1:编写接口实现类

@WebService(endpointInterface = "org.wnj.service.IMyService")  //指定接口包名类包
public class MyServiceImpl implements IMyService { /** {@inheritDoc} */ @Override
public int add(int a, int b) {
System.out.println(a + "+" + b + "=" + (a + b));
return a + b;
} /** {@inheritDoc} */ @Override
public int minus(int a, int b) {
System.out.println(a + "-" + b + "=" + (a - b));
return a - b;
} }

  

//3:启动服务

public class MyServer {

    public static void main(String[] args) {
String address = "http://localhost:8888/ns";
Endpoint.publish(address, new MyServiceImpl());
}
}

//4:编写客户端

 /** <一句话功能简述>
* <功能详细描述>
* @param args
*/
public static void main(String[] args) { try {
//创建访问wsdl服务的地址
URL url = new URL("http://localhost:8888/ns?wsdl");
//通过QName指明服务的具体信息
QName sname = new QName("http://service.wnj.org/","MyServiceImplService");
//创建服务
Service service = Service.create(url, sname);
//实现接口(最大的问题需要知道接口)
IMyService ms = service.getPort(IMyService.class);
System.out.println(ms.add(1, 2));
}
catch (MalformedURLException e) {
e.printStackTrace();
}
}

  

通过浏览器访问 : http://localhost:8888/ns?wsdl

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.1.6 in JDK 6.
-->
<!--
Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6.
-->
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://service.wnj.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://service.wnj.org/" name="MyServiceImplService">
<types>
<xsd:schema>
<xsd:import namespace="http://service.wnj.org/" schemaLocation="http://localhost:8888/ns?xsd=1"/>
</xsd:schema>
</types>
<message name="add">
<part name="parameters" element="tns:add"/>
</message>
<message name="addResponse">
<part name="parameters" element="tns:addResponse"/>
</message>
<message name="minus">
<part name="parameters" element="tns:minus"/>
</message>
<message name="minusResponse">
<part name="parameters" element="tns:minusResponse"/>
</message>
<portType name="IMyService">
<operation name="add">
<input message="tns:add"/>
<output message="tns:addResponse"/>
</operation>
<operation name="minus">
<input message="tns:minus"/>
<output message="tns:minusResponse"/>
</operation>
</portType>
<binding name="MyServiceImplPortBinding" type="tns:IMyService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="add">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="minus">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="MyServiceImplService">
<port name="MyServiceImplPort" binding="tns:MyServiceImplPortBinding">
<soap:address location="http://localhost:8888/ns"/>
</port>
</service>
</definitions>

  

WSDL标签解释

type:用来定义的传输类型,用SOAP(Simple Object Access Protool协议指定参数

mesage:用来传输SOAP消息

portType:指定服务器的接口,并且通过operation绑定方法名及相应的in,out的消息,其中in表示入参,out表示出参

binding:指定传输消息所使用的格式

service:指定服务所发布的信息

[WebService]之JWS_1的更多相关文章

  1. webService

    什么是webService WebService,顾名思义就是基于Web的服务.它使用Web(HTTP)方式,接收和响应外部系统的某种请求.从而实现远程调用.  1:从WebService的工作模式上 ...

  2. 开始webservice了

    一.WebService到底是什么 一言以蔽之:WebService是一种跨编程语言和跨操作系统平台的远程调用技术. 所谓跨编程语言和跨操作平台,就是说服务端程序采用java编写,客户端程序则可以采用 ...

  3. Spring WebService入门

    Web service是一个平台独立的,低耦合的,自包含的.基于可编程的web的应用程序,可使用开放的XML(标准通用标记语言下的一个子集)标准来描述.发布.发现.协调和配置这些应用程序,用于开发分布 ...

  4. 浅谈跨域以及WebService对跨域的支持

    跨域问题来源于JavaScript的同源策略,即只有 协议+主机名+端口号 (如存在)相同,则允许相互访问.也就是说JavaScript只能访问和操作自己域下的资源,不能访问和操作其他域下的资源. 在 ...

  5. 浅谈WebService的版本兼容性设计

    在现在大型的项目或者软件开发中,一般都会有很多种终端, PC端比如Winform.WebForm,移动端,比如各种Native客户端(iOS, Android, WP),Html5等,我们要满足以上所 ...

  6. Atitit webservice发现机制 WS-Discovery标准的规范attilax总结

    Atitit webservice发现机制 WS-Discovery标准的规范attilax总结 1.1. WS-Discovery标准1 1.2. 一.WS-Discovery1 1.2.1.   ...

  7. java调用CXF WebService接口的两种方式

    通过http://localhost:7002/card/services/HelloWorld?wsdl访问到xml如下,说明接口写对了. 2.静态调用 // 创建WebService客户端代理工厂 ...

  8. VS2010编写WebService与在IIS的发布<之简单讲解>

    工具VS2010,window环境win7 一:Webservice的创建与方法查看调用 1.新建空web应用程序项目 2.新建web服务 3.自动生成 4.直接跑起来,可以看到有2个方法 5.点击H ...

  9. webService学习之路(三):springMVC集成CXF后调用已知的wsdl接口

    webService学习之路一:讲解了通过传统方式怎么发布及调用webservice webService学习之路二:讲解了SpringMVC和CXF的集成及快速发布webservice 本篇文章将讲 ...

随机推荐

  1. Flex 容器基本概念

    申明文章出处:http://www.adobe.com/cn/devnet/flex/articles/flex-containers-tips.html Flex 4 容器可以提供一套默认的布局:B ...

  2. Maven POM.xml详解[转]

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  3. Ubuntu对FireFox安装flash插件

    有时候我们需要在Ubuntu下采用手动安装一些软件,比如Firefox的Flash插件.Adobe® Flash® Player 是一款轻量级浏览器插件,具有丰富的 Internet 应用运行时间,提 ...

  4. NDK(4)"Unresolved inclusion jni.h”的解决方法

    参考 :  http://blog.csdn.net/zhubin215130/article/details/39347873 3种解决办法: 一,重新初始化eclipse对该project的nat ...

  5. HDU 4638 Group(分组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4638 题意:给出一个数列,若干询问.每次询问区间[L,R]的最少有多少段?每一段是连续的一段且这段内的 ...

  6. 非常非常好!写了好久 k-th-smallest-in-lexicographical-order

    https://leetcode.com/problems/k-th-smallest-in-lexicographical-order/ 我没做出来.还是脑子不够清醒. 下面这个解法真的很棒很棒. ...

  7. HDU 1372 (搜索方向稍有改变) Knight Moves

    其实手写模拟一个队列也挺简单的,尤其是熟练以后. 尼玛,这题欺负我不懂国际象棋,后来百度了下,国际象棋里骑士的走法就是中国象棋里面的马 所以搜索就有八个方向 对了注意初始化标记数组的时候,不要把起点标 ...

  8. WEBUS2.0 In Action - 搜索操作指南 - (1)

    上一篇:WEBUS2.0 In Action - 索引操作指南(2) | 下一篇:WEBUS2.0 In Action - 搜索操作指南(2) 1. IQueriable中内置的搜索功能 在Webus ...

  9. oraclede chuangjian yu dajian(zhuan)

    http://wenku.baidu.com/link?url=pIKLZJ4sAurjNGjwgChqjRMhCXfn77qy1K_EW3nlGn4eN4roDN8mhSG0GakYbrTBcsD4 ...

  10. MKNetworkKit: 网络处理又一利器

    没有认识MK之前,即便ASI已经不再更新,也没有启用ASI.因为ASI对于网络的处理更偏向于底层,适合针对各种情形的扩展. 但是,今天我要开始使用 MKNetworkKit了,项目在github上,使 ...