Click here to load reader
Upload
harish-ranganathan
View
2.604
Download
0
Embed Size (px)
Citation preview
ASP.NET – WCF & REST
Harish RanganathanWeb Developer EvangelistMicrosoft Corporation India
Source: Pingdom.com
1993:Web == Content
The BrowserGeneric client experience
URI’sAddressing and identification
HTMLCommon presentation format
HyperlinksAnarchic interconnectivity
HTTP GETCommon operation everything supports
Content-Driven Web Architecture
2008:Web == Content + Capabilities
Capability-Enabled Web Architecture
Rich Browser ClientsProgrammability via script or plugins
HTTPBaseline application protocolCommon set of operations + status codes
Domain-neutral data-oriented formatsJSON, Atom/Atom PublishingRefine to support domain-specific schemas
Presentation formatsHTML, CSS
RESTful Tenents
The Web is a graph of linked ResourcesResources are identified by URI’sResources support a fixed set of operations
In practice, these are defined by HTTP
Applications follow links to achieve late binding
REST is an architectural style, not a specification
REST Continuum
Well Constructed URIs
HTTP VerbsGET – FetchPUT – Update/InsertDELETE – DeletePOST – Append
Standard Representations
RESTfullness
POST to 1 URI OKQuerystrings OK
HTTP Verbs GET – Fetch POST –
Overloaded
AJAX Services POX OK
Purists Pragmatists
webHttpBinding
New “web-friendly” WCF Binding in Fx 3.5
Allows for the development of RESTful servicesDoes not use SOAP envelopesHTTP and HTTPS Transports Only
Supports several wire formats:XMLJSONBinary (streams)
WebServiceHost
Specialized SerivceHost for RESTful services
Eliminates need for lots of configurationAutomatically configures address, binding, contract
Optimized for single-endpoint servicesUse from .svc file:<%@ ServiceHost Language="C#" Debug="true"
Service="Caching1.FeedService" Factory=“System.ServiceModel.Activation.WebServiceHostFactory” %>"%>
[WebGet] And [WebInvoke]
Binds a WCF operation to URI space and HTTP methodIndicate the HTTP Method for the operation
WebGet – Don’t make me write itWebInvoke – All verbs other than GET (Method parameter takes in the name of the Verb)
Other ParametersBodyStyle – Indicates whether the Request/ Response are wrapped or notRequestFormat – Json or XmlResponseFormat – Json or XmlUriTemplate – Rich binding to URI
UriTemplate
String that allows you to define the structure of the URI, as well as to define “Holes”
The “Holes” are variablesYou Bind the template with parameters to fill the holes
{productId} hole / variable gets bound to productId parameter in operation
[OperationContract][WebGet(UriTemplate=“product/{productId}")]Product GetProduct(int productId);
Variable
WCF REST Starter Kit
Microsoft.ServiceModel.Web.dllNew features supporting RESTful services
Visual Studio 2008 TemplatesREST Collections/Singleton ServicesAtom Feed/Atom Publishing ProtocolHTTP/POX Services
REST SamplesCodeplex Project
Released at PDCWritten by WCF teamFeatures may be included in .NET 4.0
What We've Talked About Today
REST and the “zen” of the webWCF features for REST scenarios
[WebGet] + [WebInvoke]UriTemplateWebHttpBindingAnd many more…
The WCF REST Starter KitAvailable today at http://msdn.com/wcf/rest
WebGet/WebInvoke Examples
[OperationContract][WebInvoke( Method=“PUT", ResponseFormat=WebMessageFormat.Json, UriTemplate=“product/{productId}")]Product UpdateProduct(int productId, product p);
[OperationContract][WebGet( ResponseFormat=WebMessageFormat.Json, UriTemplate=“product/{productId}")]ProductData GetProduct(int productId);
http://geekswithblogs.net/ranganh
questions
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after
the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.