WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA...

19
WCF 3.5, REST ET AL. HOW TO? Adnan Masood www.AdnanMasood.com

Transcript of WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA...

Page 1: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

WCF 3.5, REST ET AL. HOW TO?,Adnan Masoodwww.AdnanMasood.com

Page 2: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

ABOUT MEAKA. SHAMELESS SELF PROMOTION

• Sr Software Engineer / Tech Lead for Green Dot Corp (Financial • Sr. Software Engineer / Tech Lead for Green Dot Corp. (Financial Institution)

• Design and Develop Connected Systems• Involved with SoCal Dev community, co-founded San Gabriel Valley

NET D l G P bli h d h d k.NET Developers Group. Published author and speaker.• MS. Computer Science, MCPD (Enterprise Developer), MCT,

MCSD.NET• Doctoral Student - Areas of Interest: Machine learning, Bayesian g, y

Inference, Data Mining, Collaborative Filtering, Recommender Systems.

• Contact at [email protected]• Read my Blog at www AdnanMasood comRead my Blog at www.AdnanMasood.com• Doing a session in IASA 2008 in San Francisco on Aspect Oriented

Programming; for details visit http://www.iasaconnections.com

Page 3: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

AGENDA

Overview of SOA, Web Services, Design Patterns, , gWhat’s new in WCF 3.5Discuss what is REST?How to Implement REST using WCF?What are UriTemplates?How to use them in .NET 3.5?

Page 4: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

ARCHITECT IQ TEST

What are the four tenants of SOA?

Page 5: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

TENANTS OF SOA

1. Boundaries are explicit2. Services are Autonomous3. Services share Schema and Contract, not Class4. Compatibility is based upon Policy

Page 6: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

ABBR./ACRONYMS 101

f• REST • SOAP

• Representational State Transfer• Simple Object Access Protocol

• JSON • POX

• Javascript Object Notation• Plain Old XML

• RSS• ATOM

• Really Simple Syndication

Page 7: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

WHAT IS REST?

• REST is a term coined by Roy Fielding in his Ph.D dissertation [1] to g [ ]describe an architecture style of networked systems.y

[1] http://www.ebuilt.com/fielding/pubs/dissertation/top.htm

Page 8: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

REST

Representational State TransferRepresentational State Transfer

There are REST-Services and “REST-like” There are REST Services and REST-like services which use XML and HTTP but not the underlying philosophy of REST

REST outlines the philosophy of mapping HTTP b t th HTTP verbs to the Create/Retrieve/Update/Delete philosophy of APIs as discussed in a PhD thesis by Roy FieldingAPIs as discussed in a PhD thesis by Roy Fielding

Page 9: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

Examples

• http://example.com/users/ http://example.com/users/{user} (one for each user) http://example com/findUserForm http://example.com/findUserForm http://example.com/locations/ http://example.com/locations/{location} (one for each location) http://example.com/findLocationForm

Page 10: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

WCF SUPPORT TO RESTWebHttpBinding: Sends information directly p g yover HTTP or HTTPS—no SOAP envelope is created. This binding is new with the .NET Framework 3 5 version of WCF and it’s the right Framework 3.5 version of WCF, and it s the right choice for RESTful communication and other situations where SOAP isn’t required. The

ff f binding offers three options for representing content: text-based XML encoding, JavaScript Object Notation (JSON) encoding, and opaque j ( ) g, p qbinary encoding.

Page 11: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

“REPRESENTATION STATE TRANSFER” IS THEIDEA BEHIND RESOURCE ORIENTED

ARCHITECTURE

ResourceClienthttp://www.myblog.com/{year}/{month}/{day}

Blog Posts for the day

Posts 01012008 – a view and not a physical file

The Client references a Web resource using a URL. A representationof the resource is returned which can be rendered as an HTML.

Page 12: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

MOTIVATION FOR REST

"The motivation for developing REST was to create an architectural model for how the Web should work, such that it could serve as the guiding framework for the Web protocol it could serve as the guiding framework for the Web protocol standards.

REST has been applied to describe the desired Web hit t h l id tif i ti bl architecture, help identify existing problems, compare

alternative solutions, and ensure that protocol extensions would not violate the core constraints that make the Web successful."

- Roy Fielding

Page 13: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

REST VS SOAPREST VS. SOAP

Enhanced Caching – Enhanced Caching – Invocation vs. Resource

Bloat vs Simplicity– Bloat vs. Simplicity– Proxy Servers – Web evolution (semantic Web)Web evolution (semantic Web)– Generic Uri based interface via

UriTemplates (versus custom SOAP p (interface)

– Interoperability

Page 14: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

RESTFUL ARCHITECTURE BEST PRACTICES*

1. Prefer HTTP-GET over POST when a information resource URI is exposed.

2 Publish a logical URI for every programmable resource being exposed in the 2. Publish a logical URI for every programmable resource being exposed in the service.

3. Logical URI are preferred over the physical URL. The logical URL (such as : http://www.myblog.com/2008/7/2/) is better than physical URI. (http://www.myblog.com/20080702.html)

4 Create and Follow URI Template rules; this way logical URIs can modify 4. Create and Follow URI Template rules; this way logical URIs can modify the implementation without impacting client applications.

5. REST services focus on representing resources as "things" and not "actions". Th REST U i’ h bThe REST Uri’s are the nouns, not verbs.

*Roger L. Costello XML technologies course also discusses some of these points.

Page 15: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

RESTFUL ARCHITECTURE BEST PRACTICES(CONT.)( )

6. Design functional oriented read methods i.e. the GET methods should be side-effect free.

7. Use the extended information links in the responses to allow the consuming application to follow the next steps if further actions are needed.

8. As a corollary to item 6, use the extended information links for workflow actions to allow the atomic unfolding based on the current state.

9. Meaningful Uri templates are more effective than Query strings; for instance http://www.myblog.com/2008/7/2/ is more appropriate REST pattern than http://www.myblog.com/page.aspx?pageid=20080702)

10. The URL delimiter “/” should be used to represent the inheritance or “part of” relationship in the logical hierarchy. For instance http://www.myblog.com/{year}/{month}/{day}/ is more effective than h // bl /{d }/{ h}/{ }http://www.myblog.com/{day}/{month}/{year}.

Page 16: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

QUESTIONS

Page 17: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

• HTTP Programming with WCF and the NET Framework 3 5

REFERENCES

• HTTP Programming with WCF and the .NET Framework 3.5 -Justin Smithhttp://msdn.microsoft.com/msdnmag/issues/08/01/WCFinOrcas/default.aspx

• What's New for WCF in Visual Studio 2008 – Juval Lowy http://msdn.microsoft.com/msdnmag/issues/08/02/Foundations/default.aspx

• RESTful Web Services By Leonard Richardson, Sam Rubyhttp://www.amazon.com/RESTful-Web-Services-Leonard-Richardson/dp/0596529260Richardson/dp/0596529260

• Mix 2007 Talk by Don Box and Steve Maine “DEV03 -Navigating the Programmable Web” htt // i i it i /d f lt ? t 1011& i 20http://sessions.visitmix.com/default.asp?event=1011&session=2012&pid=DEV03&disc=&id=1512&year=2007&search=DEV03

Page 18: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

REFERENCES• Paul Prescod has written several excellent articles on REST:

– Second Generation Web Services• http://www.xml.com/pub/a/2002/02/06/rest.html

– REST and the Real WorldREST and the Real World• http://www.xml.com/pub/a/2002/02/20/rest.html

– SOAP, REST and Interoperability• http://www.prescod.net/rest/standardization.html

– Evaluating XML for Protocol Control DataEvaluating XML for Protocol Control Data• http://www.prescod.net/xml/envelopes/

• Wikipedia Entry on REST• http://en.wikipedia.org/wiki/Representational_State_Transfer

• Publishing RSS and ATOM Feeds using WCF 3 5 Syndication LibrariesPublishing RSS and ATOM Feeds using WCF 3.5 Syndication Libraries• http://www.codeproject.com/KB/WCF/WCF35RSSATOM.aspx

• Exploring WCF 3.5 Tools - WcfSvcHost and WcfTestClient• http://www.codeproject.com/KB/WCF/WCF35Utils.aspx

• Web Service StudioWeb Service Studio• http://www.codeplex.com/WebserviceStudio

• JSON • http://en.wikipedia.org/wiki/JSON

Page 19: WCF 3.5, REST - Adnan Masoodadnanmasood.com/content/binary/REST using WCF 3.5.pdf · TENANTS OF SOA |1. Boundaries are explicit ... • Publishing RSS and ATOM Feeds using WCF 3 5

CONCLUDING REMARKS

REST is a “new” paradigm for .NET Developers; p g p ;a new way to think about programming web services but it’s not really new since we have been using it for a long time over the webbeen using it for a long time over the web.Any Questions / Comments … feel free to contact [email protected] www.AdnanMasood.com