Condividi tramite


Book Review: WCF 4.0 Multi-tier Services Development with LINQ to Entities

The great folks at Packt Publishing contacted me to ask if I was interested in reviewing a title for them.  When I saw the title, I said “heck yes!”  The book is WCF 4.0 Multi-tier Services Development with LINQ to Entities.  I have closely followed WCF since its early days as “Indigo”, and I was excited to see a title that tackled a tough subject: using Entity Framework with WCF 4.0.

The Title

Let’s get it out of the way… this book is misnamed.  Given a book with “WCF 4.0” in the title, let alone one that focuses on “Multi-tier Services Development”, I have some specific expectations.  First, I expect multiple tiers, as in services that call other services.  I expected to see some focus on what’s new in WCF 4.0, such as the new router service and service discovery.  Since this is WCF 4.0 and the book touts that it was updated for Visual Studio 2010, I also expected to see EF 4.0 specific coverage.  I wanted to see what is new in EF4 such as POCO classes or tracking changes, especially focusing on the challenges of tracking state across tiers. 

This book is essentially a .NET 3.5 book, with basic coverage of WCF and a good intro to Entity Framework and LINQ.  It does not cover new features in .NET 4.0 and Visual Studio 2010, and does not address the topics that I expected.  That doesn’t mean it’s a bad book, it just means that the title is misleading at best.  Let’s peek into the book to see what else is in there.

Chapter 1 – Introducing Web Services and Windows Communication Foundation

I have a problem with Chapter 1 in almost every geek book.  It’s the fluff chapter, the chapter where authors waste 20-30 pages to meet a deadline.  This book is no exception here.  The author tries to introduce the reader to the concepts of a web service, SOAP, WSDL, WS-*, and tries to explain why WCF is used for this stuff.  Then the author tries to explain the architecture of WCF (address, binding, contracts, endpoints, behavior, hosting, etc) in a handful of pages.  If a developer is buying this book, I would assume they already know all this or would pick it up from context in the rest of the book.  As such, I felt chapter 1 was a waste.  I really think this is engrained in our industry, because I have gotten to where I instinctively skip chapter 1 in geek books.

Chapter 2 – Implementing a Basic HelloWorld WCF Service

Things get better here.  While I would assume that a reader buying this book should already know the basics of creating a WCF service, maybe that is not a safe assumption and you should spend a few pages on it.  I would have at least merged some of the intro material from Chapter 1 here.  Good intro material if you need it, I guess.

Getting back to the issue with this being a WCF 4.0 book… this chapter takes the reader through a somewhat painful way of creating a WCF service, including adding a .SVC file.  With WCF 4.0, hosting is much better.  The author shows how you would have done this with Visual Studio 2008, but this is not how I would show someone using WCF 4.0 to do things. 

Chapter 3 – Hosting and Debugging the HelloWorld WCF Service

The author shows how to host the WCF service in a console application, a Windows service, and IIS.  He then shows some basic debugging techniques on how to set the appropriate start-up project.  This is good intro material for a book that focuses on being an intro to WCF, but I keep getting stuck on the title here.  This is good material, and the author presents it well.  I probably would have shortened this a bit and merged with the previous chapter.  By the end of this chapter, we are on page 82.  We’ve seen some good intro material, but nothing new to WCF 4.0 and nothing tackling the tough problems that I expected due to the book’s title.

Chapter 4 – Implementing a WCF Service in the Real World

I had high hopes here, thinking we would start getting to the juicy parts.  This is basically the same as Chapter 2 with a little more code.  The author does introduce the concept of a business logic layer and discusses separating the logic from the service.  Interesting that the author uses the commonly accepted term “layer” here, I am still looking for the multiple tiers thing promised in the title.  If you are buying this book, separation of layers should be a given. 

Chapter 5 – Adding Database Support and Exception Handling to the RealNorthwind WCF Service

You would think that, by chapter 5, we would have at least seen LINQ once, and that we would start seeing Entity Framework.  Nope.  The author uses plain ol’ ADO.NET code with the System.Data.Sql provider. 

What I like about this chapter is how he introduces the fault contract and shows how the faults manifest themselves in a client application.  It could have been boiled down to a few pages in the intro section, but well done for this.

Chapter 6 – LINQ – Language Integrated Query

I enjoyed this chapter.  I think it should have been chapter 2 starting around page 30 and not chapter 6 starting on page 147.  The author does a good job of introducing the new data type var, automatic properties, object and collection initializers, and anonymous types.  He then shows lambda expressions and introduces LINQ nicely.  I have been harsh on the book, mostly for the misalignment of expectations based on the title, but this was a really well done chapter.

Chapter 7 – LINQ to Entities: Basic Concepts and Features

I enjoyed this chapter as well, although nothing in here pertains to changes in Entity Framework 4.0.  This is all EF v1 stuff, but it is very worthwhile to understand what is going on with LINQ to Entities.  This is a good introduction to LINQ to Entities and he even does a nice comparison against LINQ to SQL.  I would keep this chapter as well, although it should have been Chapter 3.

Chapter 8 – LINQ to Entities: Advanced Concepts and Features

I love the material in this chapter.  This chapter includes material on calling stored procedures, mapping stored procs to an existing entity class, using compiled queries, dynamic queries, and using inheritance.  He then dives into Table Per Hierarchy, Table Per Type, and Table Per Concrete inheritance semantics and shows examples of each.  Well done, I like the material, and fits within the scope of the book as a good candidate for a book on “Beginning Entity Framework 4.0”. 

The second half of the chapter focuses on handling concurrency and shows how to do this using a data column with ConcurrencyMode, and how to do this using a version column.  In my mind, this is the most important thing for this book to cover, and he does it very well.  I really would like to see this be the focal point of the book, showing how to handle concurrency across tiers.

Chapter 9 – Applying LINQ to Entities in a WCF Service

When I first agreed to review this title, I assumed that the book would revolve around this very concept.  How do you use LINQ to Entities in a WCF Service?  How is this different from RIA Services, what facilities are there to make this easier on you?  Is there anything in the future roadmap that promises to make this even easier? 

The author merges the concepts of concurrency and change tracking here well.  He explains that you need to query the database, detach the context, then update the context.  Wait, wha?  Oh yeah… this is EF v1 stuff.  See, in EF4, you don’t have to go through that anymore, you can change the state using ChangeState.  But if you’re going to do that, what are the approaches in a multi-tier service infrastructure?  Should you query the data store (potentially expensive) before updating, or can you propagate changes in the WCF message payload somehow to reduce the number of hits to the database?  What are the approaches and drawbacks for this approach?  Again the book’s title sets the expectation that this was updated for .NET 4.0, which is was not.

See, what I was expecting was a deeper discussion of passing messages and handling concurrent updates.  This chapter partially delivers, but I was left wanting to see more.

Chapter 10 – Distributed Transaction Support for WCF

To be as blunt as possible: if you are doing this, you are doing it wrong.  I can go on for awhile about why distributed transactions are evil, and not even a necessary evil.  There are great technologies such as Windows Workflow Foundation that provide a compensation model that should be used instead.  Do not read this material, do not use distributed transactions, favor compensation.

Recommendation

Albeit misnamed and misleading about the framework version, this is still a good book with a wealth of information in it.  I really liked a few chapters, and if you know very little about WCF or LINQ this could be a good primer for you.  It’s not a book where you will learn about WCF 4.0 or EF4.  It’s not a book that attacks the hard problems of including state in the message and leveraging a routing service effectively.  It’s not a book that effectively merges WCF and LINQ together in my opinion.  But it is a good basic introduction to those technologies for a beginner audience.

For More Information

What’s New in Entity Framework 4? Part 1: API Changes

A Developer's Introduction to Windows Communication Foundation 4