原文地址:https://www.cnblogs.com/yzw23333/p/7245104.html

Web service中一个 WSDL 对应一个 web service地址。

可以想象成一个商店,商店里面出售很多手机(portTypes),每个手机上有很多功能(opeations),每个功能对应很多输入和输出参数(message)

  • 这里没有类,只有端口。portTypes
  • 没有方法,只有端口里面的操作。opeations
  • 没有参数,只有传递给端口中某个操作的消息。message

一、WSDL文件解析

xml文档第一句:

definitions--WSDL文档的根元素,该元素的属性指明了WSDL文档的名称name,

文档的目标名字空间targetNamespace,以及WSDL文档应用的名字空间的速记定义。

它指明了此WebService的名称为:HelloWorldService

<?xml version="1.0" encoding="UTF-8"?>

<wsdl:definitions xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://test.demo1/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="HelloWorldService" targetNamespace="http://test.demo1/">

<wsdl:types>

<xs:schema xmlns:tns="http://test.demo1/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" targetNamespace="http://test.demo1/" version="1.0">

这部分是数据类型的定义,其中为定义了两个元素的结构:

  • sayHello(请求参数的类型): 将该元素定义为包含一个字符串string元素(arg0)的复合类型元素。
  • sayHelloResponse(响应参数的类型):  将该元素定义为包含一个字符串string元素(return)的复合类型元素。

其中的name="arg0", name="return"中的“arg0”,“return”是可以指定的,因为HelloWorld输入输出参数都是使用的默认的参数名,所以生成的xml是这样子。

<xs:element name="sayHello" type="tns:sayHello"/>

<xs:element name="sayHelloResponse" type="tns:sayHelloResponse"/>

<xs:complexType name="sayHello">

<xs:sequence>

  <xs:element minOccurs="0" name="arg0" type="xs:string"/>

</xs:sequence>

</xs:complexType>

<xs:complexType name="sayHelloResponse">

<xs:sequence>

  <xs:element minOccurs="0" name="return" type="xs:string"/>

</xs:sequence>

</xs:complexType>

</xs:schema>

</wsdl:types>

其中的name="arg0", name="return"中的“arg0”,“return”是可以指定的,因为HelloWorld输入输出参数都是使用的默认的参数名,所以生成的xml是这样子。

如果HelloWorld接口中的方法修改成:

1 public @WebResult(name="responseResult")String sayHello(@WebParam(name="name")String name) ;  

也就是给输入参数与返回结果指定一个选定的名字,则生成的xml如下所示:

 1 <xs:complexType name="sayHello">
2   <xs:sequence>
3     <xs:element minOccurs="0" name="name" type="xs:string"/>
4   </xs:sequence>
5 </xs:complexType>
6 <xs:complexType name="sayHelloResponse">
7   <xs:sequence>
8     <xs:element minOccurs="0" name="responseResult" type="xs:string"/>
9   </xs:sequence>
10 </xs:complexType>

下面这部分是消息格式的抽象定义,其中定义了两个消息格式:

  • sayHelloResponse( 响应消息格式 ): 由一个消息片断组成,该消息片断的名字是parameters,包含的具体元素类型是sayHelloResponse
  • sayHello( 请求消息格式 ) : 由一个消息片断组成,该消息片断的名字是 parameters,包含的具体元素类型是sayHello

<wsdl:message name="sayHelloResponse">

<wsdl:part element="tns:sayHelloResponse" name="parameters">

</wsdl:part>

</wsdl:message>

<wsdl:message name="sayHello">

<wsdl:part element="tns:sayHello" name="parameters">

</wsdl:part>

</wsdl:message>

portType---描述服务逻辑接口的operation元素的集合。HelloWorld只有一个操作sayHello.

这部分定义了服务访问点的调用模式的类型,表明 HelloWorld ServicesayHello入口类型是请求/响应模式,请求消息是sayHello,而响应消息是sayHelloResponse

<wsdl:portType name="HelloWorld">

<wsdl:operation name="sayHello">

<wsdl:input message="tns:sayHello" name="sayHello">

</wsdl:input>

<wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse">

</wsdl:output>

</wsdl:operation>

</wsdl:portType>

binding---一个endpoint的实际数据格式说明,一个binding元素定义如何将一个抽象消息映射到一个具体数据格式。该元素指明诸如参数顺序,返回值等信息。

每个被支持的信息格式和信息传送方式组合,就叫做 binding  (soap:binding 就是用 soap语言通话  )

这段xml定义的操作“sayHello”使用的是SoapDocumentProtocol消息格式(style="document")。输入和输出参数格式都是“Literal”(use="literal"

<wsdl:binding name="HelloWorldServiceSoapBinding" type="tns:HelloWorld">

<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

<wsdl:operation name="sayHello">

<soap:operation soapAction="" style="document"/>

<wsdl:input name="sayHello">

  <soap:body use="literal"/>

</wsdl:input>

<wsdl:output name="sayHelloResponse">

  <soap:body use="literal"/>

</wsdl:output>

</wsdl:operation>

</wsdl:binding>

找到名为“HelloWorldService”的service具体定义如下所示:

service---相关port元素的集合,用户组织endpoint定义。

port--通过binding和物理地址定义的endpoint,这个元素将所有抽象定义聚集在一起。

这部分是具体的Web服务的定义,在这个名为 HelloWorldService的Web服务中,

提供了一个服务访问入口,访问地址是"http://localhost:8080/helloWorld",

使用的消息模式是由前面的binding “HelloWorldServiceSoapBindin”所定义的。

<wsdl:service name="HelloWorldService">

  <wsdl:port binding="tns:HelloWorldServiceSoapBinding" name="HelloWorldPort">

    <soap:address location="http://localhost:8080/helloWorld"/>

  </wsdl:port>

</wsdl:service>

</wsdl:definitions>

二、请求及响应的具体消息格式解析

  • 请求消息

- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://test.demo1/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  
- <soapenv:Body>  
- <q0:sayHello>  
  <arg0>xxl</arg0>   
  </q0:sayHello>  
  </soapenv:Body>  
  </soapenv:Envelope>

  • 响应消息

- <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">  
- <soap:Body>  
- <sayHelloResponse xmlns:ns2="http://test.demo1/">  
  <return>hello xxl</return>   
  </sayHelloResponse>  
  </soap:Body>  
  </soap:Envelope>

学习 WebService 第二步:知识准备——WSDL文件解析的更多相关文章

  1. CocosBuilder 学习笔记(3) AnimationManager 与 ccbi 文件解析

    [CocosBuilder]学习笔记目录 1. 相关的类 先介绍和AnimationManager相关的几个类: CCBSequence 时间线.有成员duration(时间线时间,默认10秒).na ...

  2. 学习 WebService 第二步:知识准备——SOAP vs REST(wsdl和wadl区别)(转)

    原文地址:蓝精灵——默默争上游 笔记: SOAP和REST是两种实现WebService的主要方案(Web API部署REST貌似占了大半壁江山) REST Web Services 基于 HTTP ...

  3. 学习 WebService 第三步:一个简单的实例(RAD+WAS 8.5开发SOAP项目)

    [开发环境] Web Service 服务器端开发工具:RAD(Eclipse内核) Web Service 服务器:IBM WebSphere v8.5 REST/SOAP:SOAP(JAX-WS/ ...

  4. So easy Webservice 5.WSDL 文件说明

    WSDL – WebService Description Language – Web服务描述语言 通过XML形式说明服务在什么地方-地址. 通过XML形式说明服务提供什么样的方法 – 如何调用. ...

  5. webService基础知识--认识WebService

    之前在找工作的时候,有面试官问到WebService,当时没有接触过,正好现在做的项目中有用到WebService,所以就趁着业余时间来学习了. 一.简介 先来看看百度百科对WebService的解释 ...

  6. webservice系统学习笔记3-分析wsdl文件的组成

    详细分析前面章节的服务的wsdl文件 1.http://localhost:8888/ws01?wsdl 2.http://localhost:8888/ws01?xsd=1 在接口服务中添加复杂类型 ...

  7. Web Service学习笔记(webservice、soap、wsdl、jws详细分析)

    Web Service概述 Web Service的定义 W3C组织对其的定义如下,它是一个软件系统,为了支持跨网络的机器间相互操作交互而设计.Web Service服务通常被定义为一组模块化的API ...

  8. Web Service学习笔记(webservice、soap、wsdl、jws详细分析) (转)

    Web Service概述 Web Service的定义 W3C组织对其的定义如下,它是一个软件系统,为了支持跨网络的机器间相互操作交互而设计.Web Service服务通常被定义为一组模块化的API ...

  9. WebService基础学习(一)—基础知识

    一.WebService 1.什么是WebService      Web Service(WEB服务)能够快捷和方便地综合结合各种系统.商务和任何应用平台.利用最新的Web Service 标准能够 ...

随机推荐

  1. [numpy] 基础练习 (一)

    Numpy常用总结 基础要打牢,恩. 基础 # 0 - 9 arr = np.arange(10) # 3*3 bool np.full((3,3),true,dtype = bool) np.one ...

  2. _variant_t的使用

    我们先看看COM所支持的一些类型的基本类: (微软提供,在comdef.h中定义) 在COM中使用的标准类Class如下所示: _bstr_t:对BSTR类型进行打包,并提供有用的操作和方法: _co ...

  3. 【转】在MAC下使用ISO制作Linux的安装USB盘

    http://www.linuxidc.com/Linux/2013-04/82973.htm 在Mac环境下,将Linux的ISO镜像生成一个Linux的安装盘,和Linux下差不多,只是Mac下有 ...

  4. JDBC连接数据库报错:java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. ......

    问题:Java程序使用JDBC连接MySQL数据库时,控制台报错如下: java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' ...

  5. 转 WebService两种发布协议--SOAP和REST的区别

    转发文章 https://blog.csdn.net/zl834205311/article/details/62231545?ABstrategy=codes_snippets_optimize_v ...

  6. 面试:如何把xxx.sh使用/etc/init.d/xxx.sh start启动,并且可以用chkconfig配置开机自启动

    chkconfig原理: 1.脚本放到/etc/init.d下面,并且可执行(/etc/init.d/sshd) 需要被chkconfig管理,需要添加进去chkconfig  --add  sshd ...

  7. 《Spring源码深度解析》第三章 默认标签的解析

    上一章提到了,默认标签和自定义标签要分开解析.本章重点介绍默认标签的解析.在 DefaultBeanDefinitionDocumentReader 中: private void parseDefa ...

  8. 如何解决js跨域问题

    Js跨域问题是web开发人员最常碰到的一个问题之一.所谓js跨域问题,是指在一个域下的页面中通过js访问另一个不同域下的数据对象,出于安全性考 虑,几乎所有浏览器都不允许这种跨域访问,这就导致在一些a ...

  9. stm32L011F3使用开发小记——开发坏境

    今日,因工作需要,使用到了stm32L011F3芯片,此芯片基于CM0+内核,属于低功耗芯片 开发平台可以免费用于KEILMDK,keil公司用免费的许可证,网址:https://www2.keil. ...

  10. SmartGit 30天评估期结束解决办法

    smartgit 需要输入序列号解决办法: 1.找到路径: %APPDATA%\syntevo\SmartGit\<main-smartgit-version> 然后删除: setting ...