`
schy_hqh
  • 浏览: 545920 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

JAX-WS(三)wsdl详解

 
阅读更多
http://localhost:8888/numberService?wsdl
<?xml version="1.0"?>
<!-- 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 targetNamespace="http://service.hqh.com/" name="MyServiceImplService">
  <types>
    <xsd:schema>
      <xsd:import namespace="http://service.hqh.com/" schemaLocation="http://localhost:8888/numberService?xsd=1"/>
    </xsd:schema>
  </types>
  <message name="plus">
    <part name="parameters" element="tns:plus"/>
  </message>
  <message name="plusResponse">
    <part name="parameters" element="tns:plusResponse"/>
  </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="plus">
      <input message="tns:plus"/>
      <output message="tns:plusResponse"/>
    </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="plus">
      <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/numberService"/>
    </port>
  </service>
</definitions>


type节点分析
type用来定义访问的类型,即方法入参的个数,类型和返回值的类型
<definitions targetNamespace="http://service.hqh.com/" name="MyServiceImplService">
  <types>
    <xsd:schema>
      <xsd:import namespace="http://service.hqh.com/" schemaLocation="http://localhost:8888/numberService?xsd=1"/>
    </xsd:schema>
  </types>
</definitions>


http://localhost:8888/numberService?xsd=1

<?xml version="1.0"?>
<!-- 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. -->
<xs:schema version="1.0" targetNamespace="http://service.hqh.com/">
  <!--方法A的参数-->
  <xs:element name="minus" type="tns:minus"/>
  <!--方法A的返回值-->
  <xs:element name="minusResponse" type="tns:minusResponse"/>
  <!--方法B的参数-->
  <xs:element name="plus" type="tns:plus"/>
  <!--方法B的返回值-->
  <xs:element name="plusResponse" type="tns:plusResponse"/>
  <!--方法A的参数信息-->
  <xs:complexType name="minus">
    <xs:sequence>
      <xs:element name="arg0" type="xs:int"/>
      <xs:element name="arg1" type="xs:int"/>
    </xs:sequence>
  <!--方法A的返回值信息-->
  </xs:complexType>
  <xs:complexType name="minusResponse">
    <xs:sequence>
      <xs:element name="return" type="xs:int"/>
    </xs:sequence>
  </xs:complexType>
  <!--方法B的参数信息-->
  <xs:complexType name="plus">
    <xs:sequence>
      <xs:element name="arg0" type="xs:int"/>
      <xs:element name="arg1" type="xs:int"/>
    </xs:sequence>
  </xs:complexType>
  <!--方法B的返回值信息-->
  <xs:complexType name="plusResponse">
    <xs:sequence>
      <xs:element name="return" type="xs:int"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>


message节点分析
message节点用来传递消息---SOAP simple object access protocol
每个方法都有入参和返回值,这些数据就是通过message来进行传递的
客户端通过message节点传递参数到服务端,服务端执行方法,返回值又通过message节点来传递数据。一个方法至少对于2个message节点!
<?xml version="1.0"?>
<!-- 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 targetNamespace="http://service.hqh.com/" name="MyServiceImplService">
  <types>
    <xsd:schema>
      <xsd:import namespace="http://service.hqh.com/" schemaLocation="http://localhost:8888/numberService?xsd=1"/>
    </xsd:schema>
  </types>
  <!--传递plus()的入参-->
  <message name="plus">
    <part name="parameters" element="tns:plus"/>
  </message>
  <!--传递plus()返回的消息-->
  <message name="plusResponse">
    <part name="parameters" element="tns:plusResponse"/>
  </message>
  <!--传递minus()的入参-->
  <message name="minus">
    <part name="parameters" element="tns:minus"/>
  </message>
  <!--传递minus()返回的消息-->
  <message name="minusResponse">
    <part name="parameters" element="tns:minusResponse"/>
  </message>
</definitions>


portType节点分析
portType指名对外暴露的接口名称
operation 指定被访问的方法
input 指定方法的入参(指定入参对应的message)
output 指定方法的返回值(指定返回值对应的message)
<?xml version="1.0"?>
<!-- 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 targetNamespace="http://service.hqh.com/" name="MyServiceImplService">
  <types>
    <xsd:schema>
      <xsd:import namespace="http://service.hqh.com/" schemaLocation="http://localhost:8888/numberService?xsd=1"/>
    </xsd:schema>
  </types>
  <message name="plus">
    <part name="parameters" element="tns:plus"/>
  </message>
  <message name="plusResponse">
    <part name="parameters" element="tns:plusResponse"/>
  </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="plus">
      <!--方法的入参通过name="tns:plus"的message传递-->
      <input message="tns:plus"/>
      <!--方法的返回值通过name="tns:plusResponse"的message传递-->
      <output message="tns:plusResponse"/>
    </operation>
    <operation name="minus">
      <input message="tns:minus"/>
      <output message="tns:minusResponse"/>
    </operation>
  </portType>
</definitions>



binding节点分析
bingding节点主要用于指定SOAP消息以何种方式/样式进行传递
<?xml version="1.0"?>
<!-- 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 targetNamespace="http://service.hqh.com/" name="MyServiceImplService">
  <types>
    <xsd:schema>
      <xsd:import namespace="http://service.hqh.com/" schemaLocation="http://localhost:8888/numberService?xsd=1"/>
    </xsd:schema>
  </types>
  <message name="plus">
    <part name="parameters" element="tns:plus"/>
  </message>
  <message name="plusResponse">
    <part name="parameters" element="tns:plusResponse"/>
  </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="plus">
      <input message="tns:plus"/>
      <output message="tns:plusResponse"/>
    </operation>
    <operation name="minus">
      <input message="tns:minus"/>
      <output message="tns:minusResponse"/>
    </operation>
  </portType>
  <!-- 指定SOAP消息传递所使用的格式 -->
  <binding name="MyServiceImplPortBinding" type="tns:IMyService">
    <!-- SOAP使用document的风格进行传递(原来使用RBC的风格) -->
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
    <!-- plus()的消息传递 -->
    <operation name="plus">
      <soap:operation soapAction=""/>
      <!--输入消息通过literal方式进行传递(jdk1.6之前使用SOAPMessage encode方式传递)-->
      <input>
        <soap:body use="literal"/>
      </input>
      <!--输出消息通过literal-->
      <output>
        <soap:body use="literal"/>
      </output>
    </operation>
    <!-- minus()的消息传递 -->
    <operation name="minus">
      <soap:operation soapAction=""/>
      <!--输入消息通过literal方式进行传递 -->
      <input>
        <soap:body use="literal"/>
      </input>
      <!--输出消息通过literal-->
      <output>
        <soap:body use="literal"/>
      </output>
    </operation>
  </binding>
</definitions>



service节点分析
结合前面的SOAP消息传输、接口和方法(参数和返回值)的说明、SOAP消息(message)来提供一个服务
通过该服务即可调用webservice对外提供的方法
<?xml version="1.0"?>
<!-- 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 targetNamespace="http://service.hqh.com/" name="MyServiceImplService">
  <types>
    <xsd:schema>
      <xsd:import namespace="http://service.hqh.com/" schemaLocation="http://localhost:8888/numberService?xsd=1"/>
    </xsd:schema>
  </types>
  <message name="plus">
    <part name="parameters" element="tns:plus"/>
  </message>
  <message name="plusResponse">
    <part name="parameters" element="tns:plusResponse"/>
  </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="plus">
      <input message="tns:plus"/>
      <output message="tns:plusResponse"/>
    </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="plus">
      <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>
  <!--指定服务的名称(同definitions的name属性)-->
  <service name="MyServiceImplService">
    <!--prot的name属性指定的端口(一个方法)将返回服务接口的一个实现,该实现基于name="MyServiceImplPortBinding"的SOAP消息定义进行创建-->
    <port name="MyServiceImplPort" binding="tns:MyServiceImplPortBinding">
      <!--指定服务对外发布的地址-->
      <soap:address location="http://localhost:8888/numberService"/>
    </port>
  </service>
</definitions>


SOAP
SOAP通过"信封"传递消息
信封:携带方法的入参
<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
<!--对外发布的服务所在的包(逆序)-->
xmlns:q0="http://service.hqh.com/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <q0:plus>
      <arg0>1</arg0>
      <arg1>2</arg1>
    </q0:plus>
  </soapenv:Body>
</soapenv:Envelope>


信封:携带方法的返回值
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <ns2:plusResponse xmlns:ns2="http://service.hqh.com/">
      <return>3</return>
    </ns2:plusResponse>
  </S:Body>
</S:Envelope>


定制SOAP中的参数名
通过注解详细说明wsdl中的参数名称,否则默认使用args0,args1...来表示形参
服务接口中使用注解定义如下:
@WebService
public interface IMyService {
	@WebResult(name="plusResult")
	public int plus(@WebParam(name="a")int a,@WebParam(name="b")int b);
	
	@WebResult(name="minusResult")
	public int minus(@WebParam(name="a")int a,@WebParam(name="b")int b);
}



通过注解标注了参数后,SOAP中的参数名就是指定的名称了

<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:q0="http://service.hqh.com/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <q0:plus>
      <a>5</a> <!--信封中参数名称为注解所标注的名称-->
      <b>7</b> <!--信封中参数名称为注解所标注的名称-->
    </q0:plus>
  </soapenv:Body>
</soapenv:Envelope>
分享到:
评论

相关推荐

    jax-ws webservice demo

    基于jax-ws 实现的web service client和server端的demo程序。 注:如果使用的是 myeclipse 时 server 部署到tomcat 启动的时候会报错 解决办法:找到myeclipse安装目录下的 plugins 目录里 查找 webservices-rt.jar,...

    JAX-WS自学笔记

    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包

    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所需要的JAR包

    亲测可用,Jax-ws所需要的JAR包,拷贝到tomcat安装路径的lib里,实现了webservice发布到tomcat,赞!

    MyEclipse8_0中使用 JAX-WS 部署 WebService 实例

    MyEclipse8_0中使用 JAX-WS 部署 WebService 实例 - 外衣 - 博客频道 - CSDN_NET.mht

    metro-jax-ws-master

    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 ...

    webService部署tomcat需要的jax-ws jar包

    webService部署tomcat需要的jax-ws 的完整jar包

    JAX-WS_WebService.rar

    JAX-WS方式开发和部署webservice应用,JAX-WS方式开发和部署webservice应用,JAX-WS方式开发和部署webservice应用,JAX-WS方式开发和部署webservice应用,JAX-WS方式开发和部署webservice应用

    JAX-WS2.0 API

    JAX-WS2.0 API

    Jax-WS 简单实例

    Jax-WS的简单实例 Jax-WS的简单实例

    jax-rs jax-ws所需包,亲测可用

    javax.xml.ws.Service 报错需要的包,亲测可以用,直接下载在ide里buildpath一下就可以,四个jar包 ,整合了其他的jar所以配置简单

    jax-ws webservice简单demo

    jax-ws webservice完整demo,包含所有jax-ws 2.2jar包。

    基于JAX-WS2.2开发WebService所需jar资源包

    使用 Eclipse JavaEE 开发 WebService 时,若选择手动创建原生的JAX-WS服务,需要导入此jar资源(教程详见我的博文https://blog.csdn.net/weixin_50604409/article/details/116399530)。 如果您同时装有 IntelliJ ...

    JAX-WS的lib、src和docs

    JAX-WS不是一个孤立的框架,它依赖于众多其他的规范,本质上它由以下几部分组成 1.用来开发Web Services的Java API 2.用来处理Marshal/Unmarshal的XML Binding机制,JAX-WS2.0用JAXB2来处理Java Object与XML之间的映射,...

    使用JAX-WS(JWS)发布WebService

    使用JAX-WS(JWS)发布WebService 使用myeclipse开发java的webservice的两种方式 方式一: (此方式只能作为调试,有以下bug:jdk1.6u17?以下编译器不支持以Endpoint.publish方式发布document方式的soap,必须在...

    JAX-WS开发的文件生成与部署相关全视频过程

    如果基于一个JAX-WS进行WebService开发,有很多教程,但是具体怎么更自动地生成一些文件,实现客户端与服务端的交互,都讲得不大清楚,为了让大家更方便地部署,我将服务端、客户端文件的生成与部署全过程以及测试...

    JAX-WS 2.2 完整jar包

    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 方式发布web Service 后台用Hibernate实现,前端.NET通过引用服务方式实现

    rar中包含整个项目的源码和数据库生成脚本,采用jax-ws发布Web Service服务,支持java客户端和.Net客户端调用,数据库采用oracle10g,里面有创建数据库脚本文件createTable_Oracle10g.sql,由于Hibernate映射表中会...

    JAX-WS SOAP header设值

    NULL 博文链接:https://iamliming.iteye.com/blog/1399257

Global site tag (gtag.js) - Google Analytics