BT
x Your opinion matters! Please fill in the InfoQ Survey about your reading habits!

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

by Jonathan Allen on Jan 09, 2013 |

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.

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

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT