Web Services Description Language的缩写,是一个用来描述Web服务和说明如何与Web服务通信的XML语言。为用户提供详细的接口说明书。
目录
<script type="text/javascript"></script>
WSDL 简介
WSDL是Web Service的描述语言,用于描述Web Service的服务,接口绑定等WSDL 历史
在 2001 年 3 月,WSDL 1.1 被 IBM、 微软作为一个 W3C 纪录(W3C note)提交到有关 XML 协议的 W3C XML 活动,用于描述网络服务。(W3C 纪录仅供讨论。一项 W3C 纪录的发布并不代表它已被 W3C 或 W3C 团队亦或任何 W3C 成员认可。)在 2002 年 7 月,W3C 发布了第一个 WSDL 1.2 工作 草案。WSDL 功能
怎样向别人介绍你的Web service有什么功能,以及每个 函数调用时的参数呢?你可能会自己写一套文档,你甚至可能会口头上告诉需要使用你的Web service的人。这些非正式的方法至少都有一个严重的问题:当程序员坐到电脑前,想要使用你的Web service的时候,他们的工具(如Visual Studio)无法给他们提供任何帮助,因为这些工具根本就不了解你的Web service。解决方法是:用机器能阅读的方式提供一个正式的描述文档。Web service描述语言(WSDL)就是这样一个基于XML的语言,用于描述Web service及其函数、参数和返回值。因为是基于XML的,所以WSDL既是机器可阅读的,又是人可阅读的,这将是一个很大的好处。一些最新的开发工具既能根据你的Web service生成WSDL文档,又能导入WSDL文档,生成调用相应Web service的代码。WSDL 元素
WSDL 文件包含以下 元素: Type:使用某种语法(如 XML 模式)的数据类型定义(string、int) Message:要传递的数据 Part:消息参数 Operation:服务支持的操作的抽象描述 Port Type / Interface:一个或多个端点支持的操作的抽象集。此名称已更改,因此可能会遇到两者中的任何一个。 Binding:特定端口类型的具体协议和 数据格式规范 Port / Endpoint:绑定和网络地址的组合。此名称也已更改,因此可能会遇到两者中的任何一个。 Service:相关端点的集合,包括其关联的接口、操作、消息等。WSDL 文档结构
WSDL 文档是利用这些主要的元素来描述某个 web service 的: 元素 定义 web service 执行的操作 <message> web service 使用的消息 <types> web service 使用的数据类型 <binding> web service 使用的通信协议 一个 WSDL 文档的主要结构是类似这样的: <definitions> <types> definition of types........ </types> <message> definition of a message.... </message> <portType> definition of a port....... </portType> <binding> definition of a binding.... </binding> </definitions>WSDL 文档可包含其它的元素,比如 extension 元素,以及一个 service 元素,此元素可把若干个 web services 的定义组合在一个单一的 WSDL 文档中。 如需完整的语法概述,请访问 WSDL 语法 这一节。同样要记住,与服务交互所需的所有细节都位于其 WSDL 文件中。 ●WSDL支持的消息交换方式? WSDL支持4种消息交换方式: 1)单向(One-way):服务端接收消息; 2)请求响应(Request-response):服务端点接收请求消息,然后发送响应消息; 3)要求应答(Solicit-response):服务访问端发送要求消息,然后接收应答消息。 4)通知(Notification):服务访问端点发送通知消息。
<script type="text/javascript"></script>
-
扩展阅读:
-
- 1
万维网技术教程 http://www.w3course.net
- 2
w3school 在线教程 http://www.w3school.com.cn/wsdl/wsdl_intro.asp
- 1
Class: Passport.php
class Passport {
const E_USERNAME_INVALID = 1;
public $username;
public $passwd;
public $emai;
public $verifycode;
/**
* user register service
*
* @param string $username
* @param string $passwd
* @param string $email
* @param string $verifycode
*
* @return boolean
*/
public function register($username, $passwd, $email, $verifycode){
// here is register code
return $username. "\n" .
$passwd . "\n" .
$email . "\n" .
$verifycode;
}
}
WSDL: PassportSerivice.wsdl
<?xml version='1.0' encoding='UTF-8'?> <!-- WSDL file generated by Zend Studio. --> <definitions name="Passport" targetNamespace="urn:Passport" xmlns:typens="urn:Passport" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"> <message name="register"> <part name="username" type="xsd:string"/> <part name="passwd" type="xsd:string"/> <part name="email" type="xsd:string"/> <part name="verifycode" type="xsd:string"/> </message> <message name="registerResponse"> <part name="registerReturn" type="xsd:string"/> </message> <portType name="PassportPortType"> <operation name="register"> <documentation> Enter description here... </documentation> <input message="typens:register"/> <output message="typens:registerResponse"/> </operation> </portType> <binding name="PassportBinding" type="typens:PassportPortType"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="register"> <soap:operation soapAction="urn:PassportAction"/> <input> <soap:body namespace="urn:Passport" use="literal"/> </input> <output> <soap:body namespace="urn:Passport" use="literal"/> </output> </operation> </binding> <service name="PassportService"> <port name="PassportPort" binding="typens:PassportBinding"> <soap:address location="http://home/webservices/soap/new_passport/server.php"/> </port> </service> </definitions>
<?php $client = new SoapClient("http://home/webservices/soap/new_passport/PassportService.wsdl", array( "trace"=>1, "exceptions"=>0, "soap_version" => SOAP_1_2 ) ); $result = $client->register('hezhiqiang','loveit','developerworks@163.com','H6mSkD'); var_dump($result); ?>
<?php
require_once 'Passport.php';
$server = new SoapServer(
"http://home/webservices/soap/new_passport/PassportService.wsdl"
,array(
'encoding'=>'utf-8',
'soap_version' => SOAP_1_2,
'uri' => 'Passport',
'style' => SOAP_RPC,
'use' => SOAP_LITERAL)
);
$server->setClass('Passport');
$server->handle();
?>