BT

Your opinion matters! Please fill in the InfoQ Survey!

Getting Started with OData v3 and WCF Data Services 5.x

| by Jonathan Allen Follow 250 Followers on Jan 09, 2013. Estimated reading time: 1 minute |

A note to our readers: As per your request we have developed a set of features that allow you to reduce the noise, while not losing sight of anything that is important. Get email and web notifications by choosing the topics you are interested in.

If you are building new web services with .NET then OData should be high on your list of frameworks to investigate, especially if you need to support unknown third parties. The technology inherently supports both SOAP and REST style messages with the latter offering ATOM (XML) and JSON representations. This means consumers can pretty much request whatever format is best for them.

A good starting point is Mohamad Halabi’s article Understanding OData v3 and WCF Data Services 5.x. This article goes beyond the standard quick-start guide and instead focuses on the communication protocol itself.

A common misconception about WCF Data Services, Microsoft’s OData implementation, is that it is tied to their ORM Entity Framework. One of the things Mohamad shows you how to do is expose a non-EF data source. For static data this can be as simple as exposing a set of IQueryable properties back by a call to List<T>.AsQuerable. Microsoft refers to this as a Reflection Provider.

For more complex scenarios you may want to refer to the Custom Data Service Providers page on MSDN. It includes links the various interfaces you may need to implement as well as an article by the same name. Unfortunately many of the interfaces are not as well documented as one would like.

When actually setting up an OData service there are some compatibility issues you need to understand. Fortunately Mohamad also discusses the differences between OData V2 and OData V3. The main things you’ll want to pay attention to is how to register a JSONMessageInspector and the difference between JSON and JSON Light. (The latter removes much of the OData metadata.)

WCF Data Services is primarily geared towards providing CRUD style services. By that we mean create, read, update, and delete operations. You can also expose RPC style services such as a ProcessInvoice method. This is done using the WebGet and WebInvoke attributes. Unfortunately there are a lot more limitations than normal WCF services such as “each parameter must be a primitive type”. The Service Operations page covers this in more detail.

Change and query interceptors can be used to rewrite CRUD style requests. Uses range from additional validation and security checks to blocking operations with an error message explaining an alternate operation you wish to be performed.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT