REST with Silverlight 5, WCF ASP.NET

bubblemessengerΑσφάλεια

5 Νοε 2013 (πριν από 4 χρόνια και 3 μέρες)

80 εμφανίσεις

Pete Brown

Developer Community Program Manager, Microsoft

http://10rem.net, Twitter: @pete_brown,
pete.brown@microsoft.com

REST with Silverlight 5,
WCF

ASP.NET
Web API, and a little MVC 4


(AKA: Let’s see how many product names will fit in a session title)

(or, the live version of part of chapters 21 and 22 of Silverlight 5 in Action)




Where to find help


Our Community Sites


silverlight.net


windowsclient.net


asp.net



dev.windows.com



MSDN:
msdn.microsoft.com



My Blog:
10rem.net


Will include any updated source/examples

REST in a Nutshell


RE
presentational

S
tate
T
ransfer


Relies on verbs


Primarily GET, PUT, POST, DELETE


The architecture of the web



The 6 REST Constraints

Client
-
Server

A clear separation of concerns

Stateless

The server should not store any client context information between requests.

Each request is autonomous

Cacheable

Server indicates which content is cacheable,

just as we do with pages and
images today

Layered

Client is not concerned with whether or not it is connected to a specific server,
a

proxy, or something else

Code

o
n
-
d
emand

Server can send logic

to the client to execute. For example, Java applets or
Silverlight apps

Uniform interface

URIs. Self
-
descriptive messages (media types,
cacheability
, etc.)

What RESTful Services get you


Instantly accessible to any client which can make web
requests


No need for client proxies, stubs, envelopes and the other stuff
we have to deal with


Especially important with the proliferation of connected
microcontrollers


Cacheable using normal web
-
aware mechanisms


Scalable for the same reason


Flexible if you go with a full hypermedia approach

WCF

ASP.NET Web API


An API that supports you in building RESTful APIs


Does not impose REST constraints


Does not get in your way


Architected to rely on and exploit HTTP fully, not just as
a generic transport


Written by the WCF Team at Microsoft.


Now available as part of ASP.NET MVC 4


This Example

Silverlight
Client

ASP.NET MVC

ASP.NET Web API

Data

Serves

Uses

Primarily focus on the Silverlight client and Web API Server.

Project


Internal corporate application


Shared across many divisions


Control some, but not all, clients


Goals and constraints


Use
RESTful

approaches to make API available to as many clients as possible


No fat Soap envelope


No proprietary WCF formats


Make it really easy for Silverlight (or other owned clients) to use the
resources


Don’t want to recreate entities


For V1, don’t worry about security (Boy, was that convenient!)

DEMO

Stuff with semicolons and curly braces


… and the occasional angle bracket

Summary


Web API for
RESTful

“services”


Web API Now part of ASP.NET MVC


Silverlight + MVC play together nicely


Create a Razor helper for hosting Silverlight


Linked files to share model definitions


Conditional compilation or partial classes for platform
-
specific
features


My book has awesome demos



Where to find help


Our Community Sites


silverlight.net


windowsclient.net


asp.net



dev.windows.com



MSDN:
msdn.microsoft.com



My Blog:
10rem.net


Will include any updated
source/examples


Twitter:
@pete_brown


Mail
pete.brown@microsoft.com