ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R
WCF, REST, ODATA
Radu Nicolescu Department of Computer Science University of Auckland
19 Sept 2018
1 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R
1 Imperative vs Declarative
3 Windows Communication Foundation
4 Node service
5 WCF Demos
6 WCF Data Service Demos
7 WCF A#4R
2 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R Outline
1 Imperative vs Declarative
2 Open Data Protocol
3 Windows Communication Foundation
4 Node service
5 WCF Demos
6 WCF Data Service Demos
7 WCF A#4R
3 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R Imperative vs Declarative
• Imperative programming: HOW to do (usually low-level, state changes, loops)
• Declarative programming: WHAT to do (usually high-level, no state changes, no loops)
• Functional Programming (pure) • Logic Programming (pure) • Attributes - Aspect-Oriented Programming (AOP)
4 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R Imperative vs Declarative
• Imperative programming: HOW to do (usually low-level, state changes, loops)
• Declarative programming: WHAT to do (usually high-level, no state changes, no loops)
• Functional Programming (pure) • Logic Programming (pure) • Attributes - Aspect-Oriented Programming (AOP)
4 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R Outline
1 Imperative vs Declarative
2 Open Data Protocol
3 Windows Communication Foundation
4 Node service
5 WCF Demos
6 WCF Data Service Demos
7 WCF A#4R
5 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R OData – Open Data Protocol
• Open protocol which allows the creation and consumption of queryable and interoperable RESTful APIs in a simple and standard way.
• https://en.wikipedia.org/wiki/Open_Data_Protocol
• https://www.odata.org/
• OData exposes data as resources that are addressable by URIs.
• Representational state transfer (REST): Data is accessed and changed by using standard HTTP verbs of GET, PUT, POST, and DELETE.
6 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R Outline
1 Imperative vs Declarative
2 Open Data Protocol
3 Windows Communication Foundation
4 Node service
5 WCF Demos
6 WCF Data Service Demos
7 WCF A#4R
7 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R WCF – Windows Communication Foundation
• WCF is a runtime and a set of APIs in the .NET Framework for building connected, service-oriented applications.
• WCF Data Services is a component of the .NET Framework that enables you to create services that use OData to expose and consume data over the Web or intranet by using the semantics of REST.
• Uses the entity-relationship conventions of the Entity Data Model to expose resources as sets of entities that are related by associations.
8 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R WCF – Windows Communication Foundation
• WCF is a runtime and a set of APIs in the .NET Framework for building connected, service-oriented applications.
• WCF Data Services is a component of the .NET Framework that enables you to create services that use OData to expose and consume data over the Web or intranet by using the semantics of REST.
• Uses the entity-relationship conventions of the Entity Data Model to expose resources as sets of entities that are related by associations.
8 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R WCF Data Services
• EDM is high-level generic data model
• Conceptual model • Storage model • Mapping between conceptual and storage models
• Data sources
• SQL databases via Entity Framework (EF) • Other data sources via ”Reflection” (simulating an SQL database) – A#4R • Custom
9 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R WCF Data Services
• EDM is high-level generic data model
• Conceptual model • Storage model • Mapping between conceptual and storage models
• Data sources
• SQL databases via Entity Framework (EF) • Other data sources via ”Reflection” (simulating an SQL database) – A#4R • Custom
9 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R WCF Clients
• WcfClient.exe
• CURL (Client URL, aka See URL) – XCOPY
• Browser extensions: YARC (Chrome), RESTclient (FF)
• C#, F#, JS
• using URLs • using LINQ ⇒ URLs
10 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R WCF Clients
• WcfClient.exe
• CURL (Client URL, aka See URL) – XCOPY
• Browser extensions: YARC (Chrome), RESTclient (FF)
• C#, F#, JS
• using URLs • using LINQ ⇒ URLs
10 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R Outline
1 Imperative vs Declarative
2 Open Data Protocol
3 Windows Communication Foundation
4 Node service
5 WCF Demos
6 WCF Data Service Demos
7 WCF A#4R
11 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R Simple Node Service
1 const http = require(’http ’); 2 3 const hostname = ’127.0.0.1’; 4 const p o r t = 3000; 5 6 const server = http.createServer((req, res) => { 7 res.statusCode = 200; 8 res.setHeader(’Content−Type’, ’text/plain ’); 9 r e s . end (’Hello World\n ’ ) ; 10 } ); 11 12 server.listen(port, hostname, () => { 13 console.log(‘Server running at ...‘); 14 } );
12 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R Simple Node Service – Express
1 var express = require(’express ’) 2 var app = express() 3 4 app . get (’/’, function ( req , r e s ) { 5 console.log(”GET /”) 6 res.send(’Hello World’) 7 }) 8 9 app . get (”/url”, (req, res, next) => { 10 console.log(”GET /url”) 11 res.json([”James”,”Mano”,”Radu”,”Xinfeng”]); 12 } ); 13 14 app . l i s t e n (8085)
13 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R Node Service – Varia
• Advanced routing
• Parsing URL
• Dynamic content and data
• Multi-threading – background
• async, await
• Odata?
• ...
14 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R Node Service – Varia
• Advanced routing
• Parsing URL
• Dynamic content and data
• Multi-threading – background
• async, await
• Odata?
• ...
14 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R Outline
1 Imperative vs Declarative
2 Open Data Protocol
3 Windows Communication Foundation
4 Node service
5 WCF Demos
6 WCF Data Service Demos
7 WCF A#4R
15 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R WCF Ddemos
• Automatic parsing and translation URL ⇒ method calls
• Instancing models: single, multiple
• Threading models: single, multiple
• Demo: WCF Hello World
• Demo: WCF Ping Pong
16 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R Outline
1 Imperative vs Declarative
2 Open Data Protocol
3 Windows Communication Foundation
4 Node service
5 WCF Demos
6 WCF Data Service Demos
7 WCF A#4R
17 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R WCF Demos
• Demo: Data Service EF – NO manual code!
• Demo: A#4R Demo – ”reflection”, i.e. simulation of an EF model based on XML
18 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R Outline
1 Imperative vs Declarative
2 Open Data Protocol
3 Windows Communication Foundation
4 Node service
5 WCF Demos
6 WCF Data Service Demos
7 WCF A#4R
19 / 20 ImpDec OData WCF Node WCFDemo WCFDataDemo A#4R WCF A#4R
• Extension of the given demos
• Bigger, more realistic data
• null XML Entries 1
• Testing by script
• Testing tools • DO NOT change anything but the .cs/fs source!
20 / 20