武汉北大青鸟中南软件学院
400-027-0822

武汉北大青鸟-使用LoadRunner 11针对Web Services协议脚本的应用

2015-01-26供稿中心: 北大青鸟武汉中南软件学院

Web Service是基于网络的、分布式的模块化组件,它执行特定的任务,遵守具体的技术规范,这些规范使得Web Service能与其他兼容的组件进行互操作。
Web Service是基于网络的、分布式的模块化组件,它执行特定的任务,遵守具体的技术规范,这些规范使得Web Service能与其他兼容的组件进行互操作。Internet Inter-Orb Protocol(IIOP)都已经发布了很长时间了,但是这些模型都依赖于特殊对象模型协议,而Web Services利用SOAP和XML对这些模型在通信方面作了进一步的扩展以消除特殊对象模型的障碍。Web Services主要利用HTTP和SOAP协议使商业数据在Web上传输,SOAP通过HTTP调用商业对象执行远程功能调用,Web用户能够使用SOAP和HTTP通过Web调用的方法来调用远程对象。

客户根据WSDL描述文档,会生成一个SOAP请求消息,请求会被嵌入在一个HTTP POST请求中,发送到Web服务器来。Web Services部署于Web服务器端,Web服务器把这些请求转发给Web Services请求处理器。请求处理器解析收到的请求,调用Web Services,然后再生成相应的SOAP应答。Web服务器得到SOAP应答后,会再通过HTTP应答的方式把信息送回到客户端。



下面针对Web Services中的一些重要名词进行讲解。

(1)UDDI,英文为“Universal Description, Discovery and Integration”,可译为“通用描述、发现与集成服务”。UDDI是一个独立于平台的框架,用于通过使用Internet来描述服务,发现企业,并对企业服务进行集成。任何规模的行业或企业都能得益于UDDI,UDDI使用W3C和IETF*的因特网标准,比如XML、HTTP和DNS协议。在UDDI之前,还不存在一种Internet标准,可以供企业为它们的企业和伙伴提供有关其产品和服务的信息。也不存在一种方法,来集成到彼此的系统和进程中。那么UDDI有什么样的用途呢?举个例子来讲,假如航空行业发布了一个用于航班预订的UDDI标准,航空公司就可以把它们的服务注册到一个UDDI目录中。然后旅行社就能够搜索这个UDDI目录以找到航空公司预订界面。当此界面被找到后,旅行社就能够立即与此服务进行通信,这是由于它使用了一套定义良好的预订界面。

(2)WSDL英文为“Web Services Description Language”,可译为网络服务描述语言。它是一种使用XML编写的文档,可描述某个Web Service。它可规定服务的位置,以及此服务提供的操作(或方法)。WSDL文档仅仅是一个简单的XML文档,它包含一系列描述某个Web Service的定义。

以下WSDL文档的简化的片段是后续将会讲到的,这里我们先拿出来分析一下:

< message name="getTermRequest">

< part name="term" type="xs:string"/>

< /message>

< message name="getTermResponse">

< part name="value" type="xs:string"/>

< /message>

< portType name="glossaryTerms">

< operation name="getTerm">

< input message="getTermRequest"/>

< output message="getTermResponse"/>

< /operation>

< /portType>

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

< definitions xmlns="http://schemas.xmlsoap.org/wsdl/"

xmlns:xs="http://www.w3.org/2001/XMLSchema" name="IMyHelloservice"

targetNamespace="http://tempuri.org/" xmlns:tns="http://tempuri.org/"

xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"

xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/">

< message name="Welcome0Request">

< part name="name" type="xs:string" />

< /message>

< message name="Welcome0Response">

< part name="return" type="xs:string" />

< /message>

< portType name="IMyHello">

< operation name="Welcome">

< input message="tns:Welcome0Request" />

< output message="tns:Welcome0Response" />

< /operation>

< /portType>

< binding name="IMyHellobinding" type="tns:IMyHello">

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

< operation name="Welcome">

< soap:operation soapAction="urn:MyHelloIntf-IMyHello#Welcome" style="rpc" />

< input message="tns:Welcome0Request">

< soap:body use="encoded" encodingStyle=http://schemas.xmlsoap.org/soap/encoding/

namespace="urn:MyHelloIntf-IMyHello" />

< /input>

< output message="tns:Welcome0Response">

< soap:body use="encoded" encodingStyle=http://schemas.xmlsoap.org/soap/encoding/

namespace="urn:MyHelloIntf-IMyHello" />

< /output>

< /operation>

< /binding>

< service name="IMyHelloservice">

< port name="IMyHelloPort" binding="tns:IMyHellobinding">

< soap:address location="http://localhost:5678/soap/IMyHello" />

< /port>

< /service>

< /definitions>

我们可以将该WSDL 文档分成三部分。

部分:声明部分内容

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

< definitions xmlns="http://schemas.xmlsoap.org/wsdl/"

xmlns:xs="http://www.w3.org/2001/XMLSchema" name="IMyHelloservice"

targetNamespace="http://tempuri.org/" xmlns:tns="http://tempuri.org/"

xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"

xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/">

第二部分:

< message name="Welcome0Request">

< part name="name" type="xs:string" />

< /message>

< message name="Welcome0Response">

< part name="return" type="xs:string" />

< /message>

< portType name="IMyHello">

< operation name="Welcome">

< input message="tns:Welcome0Request" />

< output message="tns:Welcome0Response" />

< /operation>

< /portType>

< binding name="IMyHellobinding" type="tns:IMyHello">

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

< operation name="Welcome">

< soap:operation soapAction="urn:MyHelloIntf-IMyHello#Welcome" style="rpc" />

< input message="tns:Welcome0Request">

< soap:body use="encoded" encodingStyle=http://schemas.xmlsoap.org/soap/encoding/

namespace="urn:MyHelloIntf-IMyHello" />

< /input>

< output message="tns:Welcome0Response">

< soap:body use="encoded" encodingStyle=http://schemas.xmlsoap.org/soap/encoding/

namespace="urn:MyHelloIntf-IMyHello" />

< /output>

< /operation>

< /binding>

在这部分内容中, 元素把 " IMyHello" 定义为某个端口的名称,把 " Welcome " 定义为某个操作的名称。操作 " Welcome " 拥有一个名为 " Welcome0Request " 的输入消息,以及一个名为 " Welcome0Response " 的输出消息。 元素可定义每个消息的部件,以及相关联的数据类型。从上面的文档您不难发现,其主要有以下元素的元素来描述某个web service ,参见表13-5。

表13-5 WSDL 文档结构表

元 素

定 义

< portType>

Web Service 执行的操作

< message>

Web Service 使用的消息

< types>

Web Service 使用的数据类型

< binding>

Web Service 使用的通信协议

< portType> 元素是重要的WSDL元素。它可描述一个 Web Service、可被执行的操作,以及相关的消息。可以把元素比作传统编程语言中的一个函数库(或一个模块、或一个类)、元素定义一个操作的数据元素。每个消息均由一个或多个部件组成。可以把这些部件比作传统编程语言中一个函数调用的参数、元素定义Web Service使用的数据类型。为了大程度的平台中立性,WSDL使用XML Schema语法来定义数据类型、元素为每个端口定义消息格式和协议细节。binding元素的name属性定义binding的名称,而type属性指向用于binding的端口,在这个例子中是“ImyHello”端口。

soap:binding元素的style属性可取值“rpc”或“document”。在这个例子中我们使用rpc、transport属性定义了要使用的SOAP协议,在这个例子中我们使用HTTP。operation元素定义了每个端口提供的操作符,对于每个操作,相应的SOAP行为都需要被定义。同时您必须对输入和输出进行编码。在这个例子中我们使用了“encoded”。

第三部分:

< service name="IMyHelloservice">

< port name="IMyHelloPort" binding="tns:IMyHellobinding">

< soap:address location="http://localhost:5678/soap/IMyHello" />

< /port>

< /service>

service是一套<port>元素。在一一对应形式下,每个<port>元素都和一个location关联。如果同一个<binding>有多个<port>元素与之关联,可以使用额外的URL地址作为替换。

一个WSDL文档中可以有多个<service>元素,而且多个<service>元素十分有用,其中之一就是可以根据目标URL来组织端口。这样,我就可以方便地使用另一个<service>来重定向我的股市查询申请。我的客户端程序仍然工作,因为这种根据协议归类的服务不随服务而变化。多个<service>元素的另一个作用是根据特定的协议划分端口。例如,我可以把所有的HTTP端口放在同一个<service>中,所有的SMTP端口放在另一个<service>里。
关于我们
首页
公司简介
课程专业
师资力量
高薪就业
青鸟课程
ACCP
学士后Java
基础教育
UI设计
回到首页