Download presentation
Presentation is loading. Please wait.
2
What’s in.NET 3.5 for Services? The New HTTP Programming Model New Support for JSON Services Syndication in.NET 3.5
3
Lots of ways to create services Crescendo of features through the stack HttpListener ASP.NET ASMX WCF Sockets
4
One-stop-shop for services Consistent object model Great “ility” features 1 st released with.NET Framework 3.0 Focus on the functionality, WCF takes care of the plumbing
5
Myth: WCF is only for enterprise services Reality: WCF gets around(enterprise & web).NET 3.5 WCF web-centric upgrades: Make REST a 1 st class citizen Embrace SOAP-less representations JSON messaging capabilities Simplify working with POX RSS & Atom syndication support Run in Partial Trust (Hosting)
6
Promote web concepts to 1 st class citizens Simplify the following: mapping URIs to application logic working with HTTP methods working with Response Codes & HTTP Headers Allow SOAP & POX from the same contract Possible to do SOAP/RPC & REST from the same application
7
System.UriTemplate Type for modeling URI to application semantics Can “bind” data to a template, output a URI Can “match” a URI to a template, retrieve data System.UriTemplateMatch Returned from UriTemplate “match” operations Can get relative paths and wildcard segments System.UriTemplateTable For “binding” a URI to a group of UriTemplates
8
// create the base Uri Uri address = new Uri(“http://localhost:2000”); // create the template for a URI UriTemplate template = new UriTemplate(“{artist}/{album}”); // set the values of the URI segments Uri boundUri = template.BindByPosition(address, “Northwind”, “Overdone”); // http://localhost:2000/Northwind/Overdone Console.WriteLine(address.ToString()); // create the base Uri Uri address = new Uri(“http://localhost:2000”); // create the template for a URI UriTemplate template = new UriTemplate(“{artist}/{album}”); // set the values of the URI segments Uri boundUri = template.BindByPosition(address, “Northwind”, “Overdone”); // http://localhost:2000/Northwind/Overdone Console.WriteLine(address.ToString());
9
// address & boundUri from previous slide // use the template to parse boundUri UriTemplateMatch match = template.Match(address, boundUri); String bandName = match.BoundVariables[“artist”]; // writes “Artist name: Northwind” Console.WriteLine(“Artist name: {0}”, bandName); // address & boundUri from previous slide // use the template to parse boundUri UriTemplateMatch match = template.Match(address, boundUri); String bandName = match.BoundVariables[“artist”]; // writes “Artist name: Northwind” Console.WriteLine(“Artist name: {0}”, bandName);
10
Simple URI-to-application mapping Defaults to query string parameters [OperationContract] [WebGet(UriTemplate=“/Image/{artist}/{album}”)] Stream GetAlbumImage(String artist, String album); [OperationContract] [WebGet(UriTemplate=“/Image?name={artist})] Stream GetMainImage(String artist); [OperationContract] [WebGet(UriTemplate=“/Image/{artist}/{album}”)] Stream GetAlbumImage(String artist, String album); [OperationContract] [WebGet(UriTemplate=“/Image?name={artist})] Stream GetMainImage(String artist);
11
All HTTP verbs are 1 st class citizens GET, POST, PUT, DELETE, GET, POST, PUT, DELETE, “View It” vs “Do It” separation mimics web [OperationContract] [WebGet(UriTemplate=“/Image/{bandName}/{album}”)] Stream GetAlbumImage(String bandName, String album); [OperationContract] [WebInvoke(METHOD=“PUT”)] // {PUT, POST, DELETE} void AddAlbum(AlbumInfo albumInfo); // entity body [OperationContract] [WebGet(UriTemplate=“/Image/{bandName}/{album}”)] Stream GetAlbumImage(String bandName, String album); [OperationContract] [WebInvoke(METHOD=“PUT”)] // {PUT, POST, DELETE} void AddAlbum(AlbumInfo albumInfo); // entity body
12
WebOperationContext.Current provides access to incoming request headers Can also set outgoing response headers Some are shortcut for easier use Stream GetAlbumImage(String bandName, String album){ Stream stream; // get the image from somewhere WebOperationContext.Current.OutgoingResponse.ContentType = “image/jpeg”; return stream; } Stream GetAlbumImage(String bandName, String album){ Stream stream; // get the image from somewhere WebOperationContext.Current.OutgoingResponse.ContentType = “image/jpeg”; return stream; }
13
WebHttpBinding and WebServiceHost Use WebServiceHost/Factory in most cases Big Win – no config/behavior needed WebHttpBinding endpoint on a ServiceHost Add WebHttpBehavior to the endpoint Big Win – Compatible with existing WCF hosts Works in ASP.NET Medium Trust!
15
JavaScript Object Notation Convenient bridge: JavaScript objects Easier for browsers than XML ASP.NET AJAX & other AJAX toolkits use it Other web-aware clients also (Silverlight, etc.) var someData = {"album":"Overdone", "artist":"Northwind"}; var writeToElement = document.getElementById("RawJSON"); writeToElement.innerHTML = someData.artist + ", " + someData.album; var someData = {"album":"Overdone", "artist":"Northwind"}; var writeToElement = document.getElementById("RawJSON"); writeToElement.innerHTML = someData.artist + ", " + someData.album;
16
It’s all built on.NET 3.0 extensibility points Uses the same DataContract annotation JsonReaderWriterFactory Creates XmlDictionaryReader / Writer objects DataContractJsonSerializer Bridges objects & JSON [DataContract] public class SomeClass { [DataMember] public String SomeValue { get; set; } } [DataContract] public class SomeClass { [DataMember] public String SomeValue { get; set; } }
17
Can be simple JSON messaging Set RequestFormat / ResponseFormat Add WebHttpBehavior to endpoint Integrates with ASP.NET AJAX Add WebScriptEnablingBehavior to endpoint OR Use WebScriptServiceHost / Factory for automatic endpoint creation (0 config)
18
Full support in the client stack WCF AJAX support in Visual Studio Script manager, VS Project Templates IntelliSense for JavaScript works with JS proxies (both ASMX and WCF) Config not required Via the WebScriptServiceHostFactory (.svc file) Works in ASP.NET Medium Trust!
20
Syndications are more than news and blogs Unified object model for RSS and Atom SyndicationFeed / SyndicationItem Can be used with or without the rest of WCF Supports syndication extensions Format Agnostic RSS 2.0 & ATOM 1.0, others possible Works in ASP.NET Medium Trust!
21
[ServiceKnownType(typeof(Atom10FeedFormatter))] [ServiceKnownType(typeof(Rss20FeedFormatter))] [ServiceContract] interface IAlbumSyndication { [OperationContract] [WebGet(UriTemplate=“Images/{format}")] SyndicationFeedFormatter Feed(String format); } [ServiceKnownType(typeof(Atom10FeedFormatter))] [ServiceKnownType(typeof(Rss20FeedFormatter))] [ServiceContract] interface IAlbumSyndication { [OperationContract] [WebGet(UriTemplate=“Images/{format}")] SyndicationFeedFormatter Feed(String format); } Can decide format from URI
23
© 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.
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.