创建JWS项目步骤:

1:创建接口

2:创建实现类

3:开启服务

1:编写接口

  1. @WebService
  2. public interface IMyService {
  3.  
  4. public int add(int a,int b);
  5.  
  6. public int minus(int a,int b);
  7. }

  

1:编写接口实现类

  1. @WebService(endpointInterface = "org.wnj.service.IMyService") //指定接口包名类包
  2. public class MyServiceImpl implements IMyService {
  3.  
  4. /** {@inheritDoc} */
  5.  
  6. @Override
  7. public int add(int a, int b) {
  8. System.out.println(a + "+" + b + "=" + (a + b));
  9. return a + b;
  10. }
  11.  
  12. /** {@inheritDoc} */
  13.  
  14. @Override
  15. public int minus(int a, int b) {
  16. System.out.println(a + "-" + b + "=" + (a - b));
  17. return a - b;
  18. }
  19.  
  20. }

  

//3:启动服务

  1. public class MyServer {
  2.  
  3. public static void main(String[] args) {
  4. String address = "http://localhost:8888/ns";
  5. Endpoint.publish(address, new MyServiceImpl());
  6. }
  7. }

//4:编写客户端

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

  

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

  1. This XML file does not appear to have any style information associated with it. The document tree is shown below.
  2. <!--
  3. 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.
  4. -->
  5. <!--
  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.
  7. -->
  8. <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">
  9. <types>
  10. <xsd:schema>
  11. <xsd:import namespace="http://service.wnj.org/" schemaLocation="http://localhost:8888/ns?xsd=1"/>
  12. </xsd:schema>
  13. </types>
  14. <message name="add">
  15. <part name="parameters" element="tns:add"/>
  16. </message>
  17. <message name="addResponse">
  18. <part name="parameters" element="tns:addResponse"/>
  19. </message>
  20. <message name="minus">
  21. <part name="parameters" element="tns:minus"/>
  22. </message>
  23. <message name="minusResponse">
  24. <part name="parameters" element="tns:minusResponse"/>
  25. </message>
  26. <portType name="IMyService">
  27. <operation name="add">
  28. <input message="tns:add"/>
  29. <output message="tns:addResponse"/>
  30. </operation>
  31. <operation name="minus">
  32. <input message="tns:minus"/>
  33. <output message="tns:minusResponse"/>
  34. </operation>
  35. </portType>
  36. <binding name="MyServiceImplPortBinding" type="tns:IMyService">
  37. <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
  38. <operation name="add">
  39. <soap:operation soapAction=""/>
  40. <input>
  41. <soap:body use="literal"/>
  42. </input>
  43. <output>
  44. <soap:body use="literal"/>
  45. </output>
  46. </operation>
  47. <operation name="minus">
  48. <soap:operation soapAction=""/>
  49. <input>
  50. <soap:body use="literal"/>
  51. </input>
  52. <output>
  53. <soap:body use="literal"/>
  54. </output>
  55. </operation>
  56. </binding>
  57. <service name="MyServiceImplService">
  58. <port name="MyServiceImplPort" binding="tns:MyServiceImplPortBinding">
  59. <soap:address location="http://localhost:8888/ns"/>
  60. </port>
  61. </service>
  62. </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. 查看linux系统常用的命令,Linux查看系统配置常用命令

    一.linux CPU大小  cat /proc/cpuinfo |grep "model name" && cat /proc/cpuinfo |grep &qu ...

  2. 11.cadence.通孔类封装创建[原创]

    1.打开Pad Designer ---- ----- ---- ---- OK ------- ---- 回到Pad Designer internal:不管是几层板,中间层用这个就可以了: --- ...

  3. ZOJ 3367 Counterfeit Money(最大相同子矩阵)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3909 题意:给出两个矩阵A和B,找出最大的相同子矩阵S.输出S的高和 ...

  4. Sales Order Flow Statuses

    OE_ORDER_LINES_ALL.flow_status_code column values execute the below query to see the values. SELECT ...

  5. Android findBugs

    1.Bug:DM_BOXED_PRIMITIVE_FOR_PARSING "Boxing/unboxing to parse a primitive", A boxed primi ...

  6. Linux系统信息查看命令

    一.系统 # uname -a #查看内核/操作系统/CPU信息 # head -n 1 /etc/issue #查看操作系统版本 # cat /proc/cpuinfo #查看CPU信息 # hos ...

  7. css默认被后代inherite的属性列表

    css中的属性大部分都可以被继承,但是也有众多不能被继承,比如display, position,,left,right,top,bottom,float,width,border-color,bor ...

  8. ionic中极光推送的集成

    1.到极光官网注册账号,新建应用获得appkey. 详见:https://www.jiguang.cn/app/list 2.引入jpush插件 详见:https://github.com/jpush ...

  9. github每次推送都要输入用户名和密码

    /***************************************************************************** * github每次推送都要输入用户名和密 ...

  10. 【转】strcpy溢出的攻击示例

    在学习c/c++的时候,就讲到了一些C类型的字符串函数不是安全的,比如strcpy没有检查长度会溢出,推荐使用strncpy,笔试面试也经常问到.同时经常浏览安全相关的新闻,缓冲区溢出攻击是很常见的一 ...