從 SOA 到 RESTWeb Service 、 WCF 、 Web API 的應用情境
MIS2000 Lab. ( 微軟 MVP 2008~2016)
[email protected]://www.dotblogs.com.tw/mis2000lab
Agenda
簡介情境 Scenario (How to do ?)以前的故事 (EDI 、 B 計畫、 C 計畫)WS-* 、 WCF Service 、 Web APIWhat’s RESTfulSOAP v.s. RESTCase Study
簡 介
傳統商用程式的作法
Applications
資料來源(DB)
ConnectionString
Internet Application (Web-base)
圖片來源 http://mechittechnologies.com/webapp.php
5
加入 Web Service
ApplicationsWS-*
WCF ServiceWeb API
資料來源 (DB)
ConnectionString Uri / Url
適合多種 Client 端串連
Desk-top
Web
Mobile App
WS-*
Internet Application (Web Service-base) 圖片來源 http://mechittechnologies.com/webapp.php
8
情境 Scenario
全球簡訊發送&管理故事起源http:// 電信業者 /? 對方電話 =...& 簡訊內容
=....& 編碼 =...
OnSite Service 人員外派監控故事起源第一版,電話語音卡( CTI ),類似信用卡中心、公司總機第二版, Mobile App (手機版)重點是:我負責的程式只有一套,不需改寫。
New Hope
Applications
前端WS-*
WCF ServiceWeb API後端
資料來源(DB)
以前的故事
Hub & B2Bi
Hub
Corp A
CorpD
CorpC
Corp B
From EDI To B2Bi
美國 GXS (Global eXchange Service) EDI 、 ANSI-X12
XML 、 RosettaNet 電子商務 HL7(HealthLevelSeven) 健康資訊交換第七層協定 JSON
企業之間的對話 (RosettaNet)
資料來源 www.ec.ccu.edu.tw/book/xml/slidec/ch11.ppt
Request
Response
Request
Response
Order Request
Receipt Acknowledge
Receipt Acknowledge
Order Acceptance
Web Service 、 WCF 、 Web API
Web Service WEB服務有多種不同的方法呼叫之: 遠端程序呼叫
WEB服務提供一個分布式函數或方法接口供用戶呼叫,這是一種比較傳統的方式。通常,在WSDL中對RPC接口進行定義(類似於早期的XML-RPC)。
服務導向架構 遵從服務導向架構(Service-oriented architecture,SOA)概念來構築WEB服務。在服務導向架構中,通訊由消息驅動,而不再是某個動作(方法呼叫)。SOA方式更加關注如何連接服務而不是去特定某個實現的細節。WSDL定義了聯絡服務的必要內容。
表述性狀態轉移 表述性狀態轉移式(Representational state
transfer,REST)WEB服務類似於HTTP或其他類似協議,它們把介面限定在一組廣為人知的標準動作中(比如HTTP的GET、PUT、DELETE)以供呼叫。此類WEB服務關注與那些穩定的資源的互動,而不是消息或動作。
WCF Service
WCF (Windows Communication Foundation) 。 由微軟發展的資料通訊的應用程式開發介面 (API) ,是 .NET框架的一部分,始於 .NET Framework 3.0
WCF Service
WCF 基本概念是以合約( Contract )來定義雙方溝通的協定,合約以介面的方式呈現 實際程式碼必須要由合約介面衍生並實作。四種合約:
1. 資料合約( Data Contract ),雙方溝通時的資料格式。 2. 服務合約( Service Contract ),服務的定義。 3. 營運合約( Operation Contract ),服務提供的方法。 4. 訊息合約( Message Contract ),通訊期間覆寫訊息內容的規範。
22
WCF Service
RESTful 設計風格 REST (Representational state transfer)
REST 是設計風格 (Style) 而不是固定的標準。 REST 通常基於使用 HTTP , URI ,和 XML 以及 HTML 這些現有的協議和標準。 不像基於 SOAP 的 Web 服務, RESTful Web 服務並 沒有「正式」的標準。
以主表明細( Master-Detail )為例 列舉所有商品, GET http://www.store.com/products 呈現某一件商品, GET http://www.store.com/product/12345
Web API
ASP.NET Web API (application programming interface) 是一個架構,可輕易建置 HTTP 服務並擴及廣大的用戶端範圍,包括瀏覽器和行動裝置。
ASP.NET Web API 是一個想理平台,以 .NET Framework 基礎建置 RESTful 應用程式。
26
Web API
27
REST v.s. Web API 圖片來源 http://restlet.com/blog/2013/05/02/how-much-rest-should-your-web-api-get/
29
30
.NET 4.5 起的 One ASP.NET 概念
31
SOAP v.s. REST
SOAP v.s. REST SOAP is a protocol and REST is architecture REST supports multi-message formats, but SOAP permits
XML only. REST services are faster and easy to handle. SOAP is tied with SMTP & HTTP protocols whereas REST relies
on HTTP only. SOAP is more secure and structured format. REST don’t depend on any specific standards as it supports
various messaging formats like JSON, CSV and XML. SOAP web services allow to build the client with RESTful
services.
SOAP v.s. REST
SOAP was for distributed-computing. After REST’s entry, it accommodated the web by its
performance and scalability as a light weight component.
REST is stateless whereas SOAP is a state-ful specification.
REST uses Uniform Resource Identifier (URI) and it has methods like GET, PUT, POST and DELETE to expose their resources.
SOAP uses named operations and interfaces to achieve its business logics.
資料來源 http://www.softwaretestinghelp.com/soapui-tutorial-13-soap-vs-rest-services/
34
Case Study
Case Study .NET (C# or VB) 、工具 Visual Studio (free)
Server 端的技術Web Service WCF ServiceWeb API
Client 端的技術JavaScript jQuery
我 Blog 網站上的文章 與 範例下載 Web Service 入門 #1 ,透過 Visual Studio -- VS 2005/2008/2010 撰寫一個 Web Service (系列文章) https://dotblogs.com.tw/mis2000lab/archive/2008/09/26/webservice_1.aspx
[ 入門範例 ] ASP.NET Web Service (asmx) 與 jQuery AJAX https://dotblogs.com.tw/mis2000lab/archive/2015/05/19/jquery_ajax_web_service.aspx
Web API 超簡單入門 -- Your First ASP.NET Web API v1.0 #1 (C# / VB, 原作: Mike Wasson) (系列文章)
https://dotblogs.com.tw/mis2000lab/2012/11/01/your_first_web_api_20121101_1
Top Related