Web Service 尹伟铭 robinyin@163.net
现实举例 现有服务提供 天气预报查询服务 当地旅店咨询服务 新的服务提供 旅游网络咨询服务
现实举例(疑问1) 现有服务提供 新的服务提供 天气预报查询服务(构架在微软.Net体系) 当地旅店咨询服务(构架在IBM Java体系) 旅游网络咨询服务(如何选择??)
什么是 Web Service? From Sun Microsystems "Web Services is the clarion call of the computer software industry at present. How should we understand the term? Because of the diversity of interpretation in the industry, the easiest way is to be general and assert that Web Services means XML in motion. If the network is the computer, Web Services comprise the software that runs on it." --Simon Phipps, Chief Technology Evangelist at Sun Microsystems
什么是 Web Service? From Microsoft XML Web services are the fundamental building blocks in the move to distributed computing on the Internet. Open standards and the focus on communication and collaboration among people and applications have created an environment where XML Web services are becoming the platform for application integration. Applications are constructed using multiple XML Web services from various sources that work together regardless of where they reside or how they were implemented.
什么是 Web Service? From IBM A Web service is an application that accepts XML-formatted requests from other systems across a network (Internet or intranet) via lightweight, vendor-neutral communications protocols.
什么是 Web Service? From W3C A Web service is a software system designed to support interoperable machine-to-machine interaction over a network. It has an interface described in a machine-processable format (specifically WSDL). Other systems interact with the Web service in a manner prescribed by its description using SOAP-messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web-related standards.
Web Services In Action Web Service Web Service Database SOAP/HTTP Web Service SOAP/HTTP Database Web Service Clients
Web Service 体系结构 三个角色 三个操作 服务提供者 (Service Provider) 服务请求者 (Service Requestor) 服务代理者 (Service Registry) 三个操作 发布(UDDI & WSDL) 查找(UDDI & WSDL) 绑定(WSDL & SOAP)
Web Service WDSL SOAP WDSL UDDI WDSL,UDDI Service Provider Registry Requestor Publish Bind Find WDSL SOAP WDSL UDDI WDSL,UDDI
Client/Web Service Scenario 1: Discovery Consumer Client queries a UDDI directory over HTTP for a Location of a Web Service. Receives DISCO information Web Service
Client/Web Service Scenario 2: Service Description Consumer Client queries the Web service via HTTP for the WSDL Web Service
Client/Web Service Scenario 3: Method Description Consumer Client uses WSDL information to dynamically determine interfaces and return types Web Service
Client/Web Service Scenario 4: Method Call Consumer Client makes XML/ SOAP-encapsulated message call to the Web service, conforming to WSDL information Web Service
XML 可扩展的标记语言 XML是Web Service平台中表示数据的基本格式。除了易于建立和易于分析外,XML主要的优点在于它既与平台无关,又与厂商无关。XML是由万维网协会(W3C)创建,W3C制定的XML Schema XSD定义了一套标准的数据类型,并给出了一种语言来扩展这套数据类型。
SOAP SOAP即简单对象访问协议(Simple Object Access Protocol),它是用于交换XML编码信息的轻量级协议。它有三个主要方面:XML-envelope为描述信息内容和如何处理内容定义了框架,将程序对象编码成为XML对象的规则,执行远程过程调用(RPC)的约定。SOAP可以运行在任何其他传输协议上。例如,你可以使用 SMTP,即因特网电子邮件协议来传递SOAP消息,这可是很有诱惑力的。在传输层之间的头是不同的,但XML有效负载保持相同。
WSDL Web Service描述语言WSDL,就是用机器能阅读的方式提供的一个正式描述文档而基于XML的语言,用于描述Web Service及其函数、参数和返回值。因为是基于XML的,所以WSDL既是机器可阅读的,又是人可阅读的。
UDDI UDDI 的目的是为电子商务建立标准;UDDI是一套基于Web的、分布式的、为Web Service提供的、信息注册中心的实现标准规范,同时也包含一组使企业能将自身提供的Web Service注册,以使别的企业能够发现的访问协议的实现标准。
UDDI at Work 1. SydneyNet.com 2. 4. 3. Harbour Metal, 澳洲的一家铸铁企业 SydneyNet.com, 澳洲的一个ASP 1. SydneyNet.com UDDI Registry Harbour Metals通过本地 的 ASP创建了自身的站点 2. 客户和其他企业发现了Harbour Metals并开始与之进行e-Commerce 4. Marketplaces和search engines查询了 UBR, 缓存了Harbour Metals的技术数据 3. ASP 将 Harbour Metals 注册进了 UBR
Registry Operation Peer nodes(websites) 所有的结点都支持UDDI规范中定义的整套SOAP API 商业实体可以在任意结点注册 不同的结点将会每天定期同步复制数据 在所有结点都会包含注册数据的全集 所有的结点都支持UDDI规范中定义的整套SOAP API queries IBM Microsoft other UDDI.org HP other © Copyright 2001 by DealEasy Company, UDDI-China.org, all rights reserved.
Web Service 举例 [Web Method] public int Add(int a, int b) { return a + b; }
Web Service 举例 POST /WebService1/Service1.asmx HTTP/1.1 Host: localhost Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://tempuri.org/Add" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <Add xmlns="http://tempuri.org/"> <a>int</a> <b>int</b> </Add> </soap:Body> </soap:Envelope>
Web Service 举例 HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <AddResponse xmlns="http://tempuri.org/"> <AddResult>int</AddResult> </AddResponse> </soap:Body> </soap:Envelope>
Web Service 举例 <s:element name="Add"> <s:complexType> <s:sequence> <s:element minOccurs="1" maxOccurs="1" name="a" type="s:int" /> <s:element minOccurs="1" maxOccurs="1" name="b" type="s:int" /> </s:sequence> </s:complexType> </s:element>
释疑 通过W3C通用标准达到统一 通过HTTP与SOAP协议通讯
为什么使用Web Service Network + Servers 结构 Web + PC 结构 Web Service结构 实现本地(局域网)资源共享 没有使计算能力集中或更分散 Web + PC 结构 一种联系计算机的模式 一种分散走向集中的模式 Web Service结构
Web Service结构(Smart Client) Microsoft阵营—Web Service Rich Client or Smart Client 随时随地在线提供 使用者可以是PC也可以是有计算能力的任何设备
Web Service结构(网格计算) IBM阵营—网格,共用计算(Utility Computing) 释放PC的软硬件资源 使计算分散化,标准化,被统一的规范所调配 整个网络由各种各样但却标准的Web Service构成 分散的Web Service节点整合在网格中,为企业提供随时随地的应用 AP(孤立应用)——IS (集成系统)——SI(系统集成、互联)——WS(网格)
Web Service 与商业 明天的企业计算 明天的Matlib 明天的盗版
Web Service的缺陷 安全性/隐私权(Security/privacy) 服务质量/可靠性(Quality-of- service/reliability) 事务处理(Transaction processing) 管理(Management) 性能(Performance) 互操作性(Interoperability)