WCF Data Service Tribulations

WCF Data Services is an implementation of the OData Protocol. OData makes it easy to access and modify data from any data source. WCF Data Services makes it easy to expose a rich SQL Server data source by leveraging the Entity Framework. In traditional n-tiered services, a service tier exposes DTO’s to consumers. With WCF Data Services, the service tier is generated automatically for you! This saves a lot of manual coding, but comes with the downside of significantly reduced flexibility. I have struggled to decide if I prefer it over more traditional services due to this reduced flexibility.

How does WCF Data Services stand up to Design Principles?

Martin Fowlers “First Law of Distributed Objects” states that you should never distribute your objects. This suggests WCF Data Services is somewhat flawed since it distributes ALL your objects. The main argument of this law is that distributed objects involve far too much traffic and coarse-grained interfaces are preferable because they facilitate sending larger amounts of data at once. OData does support expand operations so that consumers can retrieve larger amounts of data, which does alleviate some of the concern surrounding sending of too much traffic.

The next principle I can find relates to the Service Layer pattern from Martin Fowler’s “Patterns of Enterprise Application Architecture”:

However, remote invocation comes at the cost of dealing with object distribution. It likely entails a lot of extra work to make your Service Layer method signatures deal in suited to Data Transfer Objects (401). Don’t underestimate the cost of this work, especially if you have a complex Domain Model (116) and rich editing UIs for comdate use cases! It’s significant, and it’s complex and painful—perhaps second only to the cost and pain of object-relational mapping.

This suggests that Service Layer DTO’s is a large complex task. WCF Data Services automates this process saving a great deal of time! This is a big advantage. Creating a rich UI with navigation and expansion of entities, maps very closely to the functionality of the built-in navigation and expansion features of OData.

Current Thoughts

OData and WCF Data Services can save a great deal of time, by removing the need to build a rich service layer. This comes with the weakness that by distributing all it’s objects, it can expose a very inefficient service. Like many tools, WCF Data Service is not a One-Size-Fits-All solution. I think it’s best suited for simpler data models, with minimal business logic. OData Service Operations provide some encapsulation, but other more mature RPC mechanisms provide greater flexibility.

Advertisements
This entry was posted in Architecture. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s