從soa到rest -- web service、wcf、webapi的應用情境

41
從 SOA 從 REST Web Service WCF Web API 從從從從 MIS2000 Lab. ( 從從 MVP 2008~2016) [email protected] http://www.dotblogs.com.tw/mis20 00lab

Upload: mis2000-lab

Post on 18-Jan-2017

1.881 views

Category:

Internet


5 download

TRANSCRIPT

Page 1: 從SOA到REST -- Web Service、WCF、WebAPI的應用情境

從 SOA 到 RESTWeb Service 、 WCF 、 Web API 的應用情境

MIS2000 Lab. ( 微軟 MVP 2008~2016)

[email protected]://www.dotblogs.com.tw/mis2000lab

Page 2: 從SOA到REST -- Web Service、WCF、WebAPI的應用情境

Agenda

簡介情境 Scenario (How to do ?)以前的故事 (EDI 、 B 計畫、 C 計畫)WS-* 、 WCF Service 、 Web APIWhat’s RESTfulSOAP v.s. RESTCase Study

Page 3: 從SOA到REST -- Web Service、WCF、WebAPI的應用情境

簡 介

Page 9: 從SOA到REST -- Web Service、WCF、WebAPI的應用情境

情境 Scenario

Page 14: 從SOA到REST -- Web Service、WCF、WebAPI的應用情境

以前的故事

Page 17: 從SOA到REST -- Web Service、WCF、WebAPI的應用情境

企業之間的對話 (RosettaNet)

資料來源 www.ec.ccu.edu.tw/book/xml/slidec/ch11.ppt

Request

Response

Request

Response

Order Request

Receipt Acknowledge

Receipt Acknowledge

Order Acceptance

Page 19: 從SOA到REST -- Web Service、WCF、WebAPI的應用情境

Web Service 、 WCF 、 Web API

Page 20: 從SOA到REST -- Web Service、WCF、WebAPI的應用情境

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服務關注與那些穩定的資源的互動,而不是消息或動作。

Page 22: 從SOA到REST -- Web Service、WCF、WebAPI的應用情境

WCF Service

WCF 基本概念是以合約( Contract )來定義雙方溝通的協定,合約以介面的方式呈現 實際程式碼必須要由合約介面衍生並實作。四種合約:

1. 資料合約( Data Contract ),雙方溝通時的資料格式。 2. 服務合約( Service Contract ),服務的定義。 3. 營運合約( Operation Contract ),服務提供的方法。 4. 訊息合約( Message Contract ),通訊期間覆寫訊息內容的規範。

22

Page 24: 從SOA到REST -- Web Service、WCF、WebAPI的應用情境

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

Page 30: 從SOA到REST -- Web Service、WCF、WebAPI的應用情境

30

Page 32: 從SOA到REST -- Web Service、WCF、WebAPI的應用情境

SOAP v.s. REST

Page 33: 從SOA到REST -- Web Service、WCF、WebAPI的應用情境

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.

Page 34: 從SOA到REST -- Web Service、WCF、WebAPI的應用情境

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

Page 39: 從SOA到REST -- Web Service、WCF、WebAPI的應用情境

Case Study

Page 41: 從SOA到REST -- Web Service、WCF、WebAPI的應用情境

我 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