SlideShare a Scribd company logo
1 of 29
Download to read offline
REST, JSON and RSS with
Windows Communication
Foundation 3.5


Rob Windsor
ObjectSharp Consulting
rwindsor@objectsharp.com
Me.About

 Visual Basic MVP
 Senior Consultant with ObjectSharp Consulting
 President of the Toronto Visual Basic User
 Group
 Member of the MSDN Canada Speakers Bureau
 Contact me via my blog
   http://msmvps.com/windsor
Agenda
 WCF Overview
 JSON Services
 HTTP Programming Model
 Syndication
Windows Communication Foundation
  One-stop-shop for services
  Consistent object model
  First released with .NET Framework 3.0

Focus on the functionality, WCF takes care of the
                    plumbing
The ABCs of WCF


  Client                                             Service
                                           A     B   C

           C   B    A        Message       A     B   C




               Address       Binding   Contract
                   (Where)    (How)     (What)
WCF Standard Bindings
Name                    Transport    Encoding     Interop
BasicHttpBinding        HTTP/HTTPS   Text         Yes
NetTcpBinding           TCP          Binary       No
NetPeerTcpBinding       P2P          Binary       No
NetNamedPipeBinding     IPC          Binary       No
WSHttpBinding           HTTP/HTTPS   Text, MTOM   Yes
WSFederationBinding     HTTP/HTTPS   Text, MTOM   Yes
WSDualHttpBinding       HTTP/HTTPS   Text, MTOM   Yes
NetMsmqBinding          MSMQ         Binary       No
NetIntegrationBinding   MSMQ         Binary       Yes
WCF Services
Agenda
 WCF Overview
 JSON Services
 HTTP Programming Model
 Syndication
What is JSON?
  JavaScript Object Notation
  Format for bridging JavaScript and objects
     Easier for browsers than XML
  ASP.NET AJAX & other AJAX toolkits use it
     Other web-aware clients also (Silverlight, etc.)


var data = {“temp” : 59, “descr” : “cloudy”};
document.write (“The weather is “ + data.descr);
WCF / AJAX Integration
 WCF AJAX support in Visual Studio
    Script manager, VS Project Templates
 WCF automatically generates JS proxy
 Usage pattern similar to existing one:
    Add service to Script Manager control
    Write JavaScript code to work with proxy
 Configuration not required
    Via the WebScriptServiceHostFactory (.svc file)


       Works in ASP.NET Medium Trust!
JSON Services
Agenda
 WCF Overview
 JSON Services
 HTTP Programming Model
 Syndication
Web Concepts (REST)
 Embrace the URI
    Segments map to application logic
 HTTP GET is special
    GET is idempotent (View It)
     Multiple GETs to a URI should produce the same (or similar)
     results
    PUT / POST / DELETE do “stuff” (Do It)
 Content-type header is the data model
    Image, XML, JSON, etc.
The Web, the URI, and Apps

objectsharp.com/artists/Flaming+Hammer/HitMe
objectsharp.com/artists/Northwind/Overdone


objectsharp.com/artists/{artist}/{album}



objectsharp.com/artists/Flaming+Hammer?album=HitMe
objectsharp.com/artists/Northwind?album=Overdone


objectsharp.com/astists/{artist}?album={album}
Modeling a URI in .NET 3.5
 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
Roundtrip Data in a URI

Uri address = new Uri(“http://localhost:2000”);
UriTemplate template =
 new UriTemplate(“{artist}/{album}”);
Uri boundUri =
 template.BindByPosition(address,
                         “Northwind”, “Overdone”);
UriTemplateMatch match = template.Match(address,
                                        boundUri);
String bandName = match.BoundVariables[“artist”];
URIs in WCF Contracts
 Simple URI-to-application mapping


[OperationContract]
[WebGet(UriTemplate=“/Image/{artist}/{album}”)]
Stream GetAlbumImage(String artist, String album);


[OperationContract]
[WebGet(UriTemplate=“/Image?name={artist})]
Stream GetMainImage(String artist);
HTTP Verbs in WCF Contracts
 All HTTP verbs are first class citizens
    GET, POST, PUT, etc.
 “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);
Data Formats and the Web
 HTTP headers can indicate
    Accepted data formats (Request)
    The format of the returned data (Response)
 Common header names:
    Accept (Request), Content-Type (Response)
 Small sampling of varieties:
    text/html, text/css,
    image/gif, image/jpeg,
    application/atom+xml, application/json,
    video/mp4
Specifying Data Format in WCF
    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;
}
Hosting / Binding
 WebHttpBinding endpoint on a ServiceHost
    Add WebHttpBehavior to the endpoint
 Use WebServiceHost/Factory in most cases
 Web endpoints do not support WSDL

      Works in ASP.NET Medium Trust!
View It and Do It
Agenda
 Level-set
 JSON Services
 HTTP Programming Model
 Syndication
Syndication Goals in .NET 3.5
 Syndications are more than news and blogs
    Representation of any set of data
    Usually slowly changing
 Unified object model for RSS and Atom
    SyndicationFeed / SyndicationItem
 Feeds are service operations
 Consume as a service or as document
Syndication in .NET Fx 3.5
 Single stop for syndications
    Create and Consume with or without WCF
 Easy to use object model
 Transport Agnostic
 Supports syndication extensions
 Format Agnostic
    RSS 2.0 & ATOM 1.0, others possible

           Works in ASP.NET Medium Trust!
Syndication Contracts in WCF


[ServiceKnownType(typeof(Atom10FeedFormatter))]
[ServiceKnownType(typeof(Rss20FeedFormatter))]
[ServiceContract]
interface IAlbumSyndication {
    [OperationContract]
    [WebGet(UriTemplate=“Images/{format}quot;)]
    SyndicationFeedFormatter<SyndicationFeed>
     Feed(String format);
}
Syndication with PictureServices
Web Centric Features in WCF 3.5

 Simple HTTP service development
 SOAP and POX from the same contract
 JSON messaging capability
 Simple syndication – really!



                  Built on WCF
                extensibility points
                  from .NET 3.0
Resources
 Microsoft WCF Community Site
   http://wcf.netfx3.com/
 PictureServices Samples
   http://www.cloudsamples.net/pictureservices/
 The EndPoint on Channel 9
   http://channel9.msdn.com/shows/The_EndPoint
 Justin Smith’s Blog
   http://blogs.msdn.com/justinjsmith/
 Steve Maine’s Blog
   http://hyperthink.net/blog/
 Getting Started with WCF
   http://msdn2.microsoft.com/en-us/vbasic/bb736015.aspx

More Related Content

What's hot

Beginning with wcf service
Beginning with wcf serviceBeginning with wcf service
Beginning with wcf service
Binu Bhasuran
 
Interoperability and Windows Communication Foundation (WCF) Overview
Interoperability and Windows Communication Foundation (WCF) OverviewInteroperability and Windows Communication Foundation (WCF) Overview
Interoperability and Windows Communication Foundation (WCF) Overview
Jorgen Thelin
 
Windows Communication Foundation (WCF) Service
Windows Communication Foundation (WCF) ServiceWindows Communication Foundation (WCF) Service
Windows Communication Foundation (WCF) Service
Sj Lim
 
1. WCF Services - Exam 70-487
1. WCF Services - Exam 70-4871. WCF Services - Exam 70-487
1. WCF Services - Exam 70-487
Bat Programmer
 
Session 1: The SOAP Story
Session 1: The SOAP StorySession 1: The SOAP Story
Session 1: The SOAP Story
ukdpe
 

What's hot (20)

WCF And ASMX Web Services
WCF And ASMX Web ServicesWCF And ASMX Web Services
WCF And ASMX Web Services
 
Beginning with wcf service
Beginning with wcf serviceBeginning with wcf service
Beginning with wcf service
 
Building RESTful Services with WCF 4.0
Building RESTful Services with WCF 4.0Building RESTful Services with WCF 4.0
Building RESTful Services with WCF 4.0
 
Windows Communication Foundation (WCF)
Windows Communication Foundation (WCF)Windows Communication Foundation (WCF)
Windows Communication Foundation (WCF)
 
Wcf architecture overview
Wcf architecture overviewWcf architecture overview
Wcf architecture overview
 
WCF
WCFWCF
WCF
 
Introduction to WCF
Introduction to WCFIntroduction to WCF
Introduction to WCF
 
WCF for begineers
WCF  for begineersWCF  for begineers
WCF for begineers
 
Interoperability and Windows Communication Foundation (WCF) Overview
Interoperability and Windows Communication Foundation (WCF) OverviewInteroperability and Windows Communication Foundation (WCF) Overview
Interoperability and Windows Communication Foundation (WCF) Overview
 
WCF
WCFWCF
WCF
 
WCF tutorial
WCF tutorialWCF tutorial
WCF tutorial
 
Windows Communication Foundation (WCF) Best Practices
Windows Communication Foundation (WCF) Best PracticesWindows Communication Foundation (WCF) Best Practices
Windows Communication Foundation (WCF) Best Practices
 
Windows Communication Foundation (WCF) Service
Windows Communication Foundation (WCF) ServiceWindows Communication Foundation (WCF) Service
Windows Communication Foundation (WCF) Service
 
1. WCF Services - Exam 70-487
1. WCF Services - Exam 70-4871. WCF Services - Exam 70-487
1. WCF Services - Exam 70-487
 
Session 1: The SOAP Story
Session 1: The SOAP StorySession 1: The SOAP Story
Session 1: The SOAP Story
 
Web services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows FormsWeb services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows Forms
 
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUI
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUIAdvancio, Inc. Academy: Web Sevices, WCF & SOAPUI
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUI
 
Understanding Web Services by software outsourcing company india
Understanding Web Services by software outsourcing company indiaUnderstanding Web Services by software outsourcing company india
Understanding Web Services by software outsourcing company india
 
Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)
 
Top wcf interview questions
Top wcf interview questionsTop wcf interview questions
Top wcf interview questions
 

Viewers also liked

ERP Highlights £ Điểm nổi bật của ERP
ERP Highlights £ Điểm nổi bật của ERPERP Highlights £ Điểm nổi bật của ERP
ERP Highlights £ Điểm nổi bật của ERP
Thuc Pham Chuc Nang
 
RESTful services
RESTful servicesRESTful services
RESTful services
gouthamrv
 

Viewers also liked (12)

AJITH_S
AJITH_SAJITH_S
AJITH_S
 
Direccion del proyecto (1)
Direccion del proyecto (1)Direccion del proyecto (1)
Direccion del proyecto (1)
 
Advice for rural development
Advice for rural developmentAdvice for rural development
Advice for rural development
 
REST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A TourREST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A Tour
 
Tarea sesion 3
Tarea sesion 3Tarea sesion 3
Tarea sesion 3
 
ERP Highlights £ Điểm nổi bật của ERP
ERP Highlights £ Điểm nổi bật của ERPERP Highlights £ Điểm nổi bật của ERP
ERP Highlights £ Điểm nổi bật của ERP
 
RESTful services
RESTful servicesRESTful services
RESTful services
 
Hybris 6.0.0 to 6.3.0 comparision
Hybris 6.0.0 to 6.3.0 comparisionHybris 6.0.0 to 6.3.0 comparision
Hybris 6.0.0 to 6.3.0 comparision
 
Resume_VipinKP
Resume_VipinKPResume_VipinKP
Resume_VipinKP
 
Building and deploying microservices with event sourcing, CQRS and Docker (Be...
Building and deploying microservices with event sourcing, CQRS and Docker (Be...Building and deploying microservices with event sourcing, CQRS and Docker (Be...
Building and deploying microservices with event sourcing, CQRS and Docker (Be...
 
Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)
 
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
 

Similar to REST, JSON and RSS with WCF 3.5

Building+restful+webservice
Building+restful+webserviceBuilding+restful+webservice
Building+restful+webservice
lonegunman
 
DEV301- Web Service Programming with WCF 3.5
DEV301- Web Service Programming with WCF 3.5DEV301- Web Service Programming with WCF 3.5
DEV301- Web Service Programming with WCF 3.5
Eyal Vardi
 
Xml web services
Xml web servicesXml web services
Xml web services
Raghu nath
 
Json-based Service Oriented Architecture for the web
Json-based Service Oriented Architecture for the webJson-based Service Oriented Architecture for the web
Json-based Service Oriented Architecture for the web
kriszyp
 
DevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp NetDevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp Net
Adil Mughal
 
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Igor Moochnick
 
Intro to web services
Intro to web servicesIntro to web services
Intro to web services
Neil Ghosh
 

Similar to REST, JSON and RSS with WCF 3.5 (20)

Building+restful+webservice
Building+restful+webserviceBuilding+restful+webservice
Building+restful+webservice
 
DEV301- Web Service Programming with WCF 3.5
DEV301- Web Service Programming with WCF 3.5DEV301- Web Service Programming with WCF 3.5
DEV301- Web Service Programming with WCF 3.5
 
Xml web services
Xml web servicesXml web services
Xml web services
 
Reusing Existing Java EE Applications from SOA Suite 11g
Reusing Existing Java EE Applications from SOA Suite 11gReusing Existing Java EE Applications from SOA Suite 11g
Reusing Existing Java EE Applications from SOA Suite 11g
 
Json-based Service Oriented Architecture for the web
Json-based Service Oriented Architecture for the webJson-based Service Oriented Architecture for the web
Json-based Service Oriented Architecture for the web
 
ASP.NET WEB API Training
ASP.NET WEB API TrainingASP.NET WEB API Training
ASP.NET WEB API Training
 
jkljklj
jkljkljjkljklj
jkljklj
 
RESTful WCF Services
RESTful WCF ServicesRESTful WCF Services
RESTful WCF Services
 
DevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp NetDevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp Net
 
Practical OData
Practical ODataPractical OData
Practical OData
 
Interoperable Web Services with JAX-WS and WSIT
Interoperable Web Services with JAX-WS and WSITInteroperable Web Services with JAX-WS and WSIT
Interoperable Web Services with JAX-WS and WSIT
 
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
 
AK 3 web services using apache axis
AK 3   web services using apache axisAK 3   web services using apache axis
AK 3 web services using apache axis
 
Intro to web services
Intro to web servicesIntro to web services
Intro to web services
 
Web API or WCF - An Architectural Comparison
Web API or WCF - An Architectural ComparisonWeb API or WCF - An Architectural Comparison
Web API or WCF - An Architectural Comparison
 
.Net3.5 Overview
.Net3.5 Overview.Net3.5 Overview
.Net3.5 Overview
 
Introducing SOA and Oracle SOA Suite 11g for Database Professionals
Introducing SOA and Oracle SOA Suite 11g for Database ProfessionalsIntroducing SOA and Oracle SOA Suite 11g for Database Professionals
Introducing SOA and Oracle SOA Suite 11g for Database Professionals
 
Web 2 0 Tools
Web 2 0 ToolsWeb 2 0 Tools
Web 2 0 Tools
 
Divide et impera
Divide et imperaDivide et impera
Divide et impera
 
SOA and web services
SOA and web servicesSOA and web services
SOA and web services
 

More from Rob Windsor

Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010
Rob Windsor
 
Integrating SharePoint 2010 and Visual Studio Lightswitch
Integrating SharePoint 2010 and Visual Studio LightswitchIntegrating SharePoint 2010 and Visual Studio Lightswitch
Integrating SharePoint 2010 and Visual Studio Lightswitch
Rob Windsor
 
SharePoint 2010 Application Development Overview
SharePoint 2010 Application Development OverviewSharePoint 2010 Application Development Overview
SharePoint 2010 Application Development Overview
Rob Windsor
 

More from Rob Windsor (7)

JavaScript and jQuery for SharePoint Developers
JavaScript and jQuery for SharePoint DevelopersJavaScript and jQuery for SharePoint Developers
JavaScript and jQuery for SharePoint Developers
 
Introduction to the SharePoint Client Object Model and REST API
Introduction to the SharePoint Client Object Model and REST APIIntroduction to the SharePoint Client Object Model and REST API
Introduction to the SharePoint Client Object Model and REST API
 
Advanced SharePoint Web Part Development
Advanced SharePoint Web Part DevelopmentAdvanced SharePoint Web Part Development
Advanced SharePoint Web Part Development
 
Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010
 
Integrating SharePoint 2010 and Visual Studio Lightswitch
Integrating SharePoint 2010 and Visual Studio LightswitchIntegrating SharePoint 2010 and Visual Studio Lightswitch
Integrating SharePoint 2010 and Visual Studio Lightswitch
 
SharePoint 2010 Application Development Overview
SharePoint 2010 Application Development OverviewSharePoint 2010 Application Development Overview
SharePoint 2010 Application Development Overview
 
Integrating ASP.NET AJAX with SharePoint
Integrating ASP.NET AJAX with SharePointIntegrating ASP.NET AJAX with SharePoint
Integrating ASP.NET AJAX with SharePoint
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

REST, JSON and RSS with WCF 3.5

  • 1. REST, JSON and RSS with Windows Communication Foundation 3.5 Rob Windsor ObjectSharp Consulting rwindsor@objectsharp.com
  • 2. Me.About Visual Basic MVP Senior Consultant with ObjectSharp Consulting President of the Toronto Visual Basic User Group Member of the MSDN Canada Speakers Bureau Contact me via my blog http://msmvps.com/windsor
  • 3. Agenda WCF Overview JSON Services HTTP Programming Model Syndication
  • 4. Windows Communication Foundation One-stop-shop for services Consistent object model First released with .NET Framework 3.0 Focus on the functionality, WCF takes care of the plumbing
  • 5. The ABCs of WCF Client Service A B C C B A Message A B C Address Binding Contract (Where) (How) (What)
  • 6. WCF Standard Bindings Name Transport Encoding Interop BasicHttpBinding HTTP/HTTPS Text Yes NetTcpBinding TCP Binary No NetPeerTcpBinding P2P Binary No NetNamedPipeBinding IPC Binary No WSHttpBinding HTTP/HTTPS Text, MTOM Yes WSFederationBinding HTTP/HTTPS Text, MTOM Yes WSDualHttpBinding HTTP/HTTPS Text, MTOM Yes NetMsmqBinding MSMQ Binary No NetIntegrationBinding MSMQ Binary Yes
  • 8. Agenda WCF Overview JSON Services HTTP Programming Model Syndication
  • 9. What is JSON? JavaScript Object Notation Format for bridging JavaScript and objects Easier for browsers than XML ASP.NET AJAX & other AJAX toolkits use it Other web-aware clients also (Silverlight, etc.) var data = {“temp” : 59, “descr” : “cloudy”}; document.write (“The weather is “ + data.descr);
  • 10. WCF / AJAX Integration WCF AJAX support in Visual Studio Script manager, VS Project Templates WCF automatically generates JS proxy Usage pattern similar to existing one: Add service to Script Manager control Write JavaScript code to work with proxy Configuration not required Via the WebScriptServiceHostFactory (.svc file) Works in ASP.NET Medium Trust!
  • 12. Agenda WCF Overview JSON Services HTTP Programming Model Syndication
  • 13. Web Concepts (REST) Embrace the URI Segments map to application logic HTTP GET is special GET is idempotent (View It) Multiple GETs to a URI should produce the same (or similar) results PUT / POST / DELETE do “stuff” (Do It) Content-type header is the data model Image, XML, JSON, etc.
  • 14. The Web, the URI, and Apps objectsharp.com/artists/Flaming+Hammer/HitMe objectsharp.com/artists/Northwind/Overdone objectsharp.com/artists/{artist}/{album} objectsharp.com/artists/Flaming+Hammer?album=HitMe objectsharp.com/artists/Northwind?album=Overdone objectsharp.com/astists/{artist}?album={album}
  • 15. Modeling a URI in .NET 3.5 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
  • 16. Roundtrip Data in a URI Uri address = new Uri(“http://localhost:2000”); UriTemplate template = new UriTemplate(“{artist}/{album}”); Uri boundUri = template.BindByPosition(address, “Northwind”, “Overdone”); UriTemplateMatch match = template.Match(address, boundUri); String bandName = match.BoundVariables[“artist”];
  • 17. URIs in WCF Contracts Simple URI-to-application mapping [OperationContract] [WebGet(UriTemplate=“/Image/{artist}/{album}”)] Stream GetAlbumImage(String artist, String album); [OperationContract] [WebGet(UriTemplate=“/Image?name={artist})] Stream GetMainImage(String artist);
  • 18. HTTP Verbs in WCF Contracts All HTTP verbs are first class citizens GET, POST, PUT, etc. “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);
  • 19. Data Formats and the Web HTTP headers can indicate Accepted data formats (Request) The format of the returned data (Response) Common header names: Accept (Request), Content-Type (Response) Small sampling of varieties: text/html, text/css, image/gif, image/jpeg, application/atom+xml, application/json, video/mp4
  • 20. Specifying Data Format in WCF 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; }
  • 21. Hosting / Binding WebHttpBinding endpoint on a ServiceHost Add WebHttpBehavior to the endpoint Use WebServiceHost/Factory in most cases Web endpoints do not support WSDL Works in ASP.NET Medium Trust!
  • 22. View It and Do It
  • 23. Agenda Level-set JSON Services HTTP Programming Model Syndication
  • 24. Syndication Goals in .NET 3.5 Syndications are more than news and blogs Representation of any set of data Usually slowly changing Unified object model for RSS and Atom SyndicationFeed / SyndicationItem Feeds are service operations Consume as a service or as document
  • 25. Syndication in .NET Fx 3.5 Single stop for syndications Create and Consume with or without WCF Easy to use object model Transport Agnostic Supports syndication extensions Format Agnostic RSS 2.0 & ATOM 1.0, others possible Works in ASP.NET Medium Trust!
  • 26. Syndication Contracts in WCF [ServiceKnownType(typeof(Atom10FeedFormatter))] [ServiceKnownType(typeof(Rss20FeedFormatter))] [ServiceContract] interface IAlbumSyndication { [OperationContract] [WebGet(UriTemplate=“Images/{format}quot;)] SyndicationFeedFormatter<SyndicationFeed> Feed(String format); }
  • 28. Web Centric Features in WCF 3.5 Simple HTTP service development SOAP and POX from the same contract JSON messaging capability Simple syndication – really! Built on WCF extensibility points from .NET 3.0
  • 29. Resources Microsoft WCF Community Site http://wcf.netfx3.com/ PictureServices Samples http://www.cloudsamples.net/pictureservices/ The EndPoint on Channel 9 http://channel9.msdn.com/shows/The_EndPoint Justin Smith’s Blog http://blogs.msdn.com/justinjsmith/ Steve Maine’s Blog http://hyperthink.net/blog/ Getting Started with WCF http://msdn2.microsoft.com/en-us/vbasic/bb736015.aspx