Archive

Posts Tagged ‘Michele Leroux Bustamante’

A Practical Architecture for WCF – Part 1

August 20, 2009 Leave a comment

This is the first in a series of articles designed to provide an example of a practical architecture for WCF in its support of a services oriented architecture.

We are going to look at how you could take an existing web site and wrap its functionality in services to be consumed by either a web site or a windows forms application.  We will show you how to configure your network and servers to offer these services across domains and machine boundaries.  We’ll also take a look at how to structure data contracts to provide robust objects and lists of objects across the wire with exception reporting.  Finally we’ll look at how to configure support for distributed transactions and some suggestions for structuring projects to make testing and deployment easier.

There are a few references that I recommend using as you are learning WCF and they are posted here on the Computer Mutt.  Those resources will address a wider range of WCF concepts much more in-depth than I will here as this article is focused on providing an approach to a particular problem, and not structured to review all options that are available.  Michelle Leroux’s introduction in the chapter on working with WCF in Visual Studio 2008 which covers SOA and WCF is total gold, and every time I re-read it I get something out of it.

Ok, let’s take the first step look at what we have and what we want to wind up with.  We are starting out with a current web site that site is a very simple ASP.NET 3.5 public web application in production that provides a list of cheese brands and cheese types that are made without animal rennet.   It has discreet layers consisting of a data layer, business layer and presentation layer in the form of web pages.  The data layer talks to Microsoft SQL Server 2008 and runs on IIS7 on Windows Server 2008.  Everything is 64 bit and everything is on a single box.  Basically it is simple running website and thus a good candidate for a first step.

Here is a network diagram showing the current architecture of the website we are going to transform:

Current Architecture

The diagram below is what the architecture will look like after we transform it.  The differences are that major components are separated by machine boundaries.  The database has its own box, services has its own box, and the web site has its own box.  On the services box we also have the original business and data layers along with IIS.  

Once we transform our original website and began offering services, we are simply serving content to presentation layers both inside and outside of your network allowing you to use either browsers or Windows Forms applications.  In the case of a browser, the user points to a URL to get content, in your Windows Forms application, you can configure an endpoint to point to, either way, desktop configuration and support can be much simpler as a result.

Configuring the environment for services behind the firewall is simpler than offering them over the network, and the scope of this series is for services on the inside of the firewall.  In a subsequent article, I’ll walk you through the steps necessary to offer secure services over the internet.

NewArchitecture

We are going to use Visual Studio 2008 with .NET 3.5 along with WCF Services Templates to code services.  Development is on a Vista machine.  An aside on Vista first.  I’ve heard how Vista sucked and to avoid it, however when I switched to developing and supporting ASP.NET apps on Windows Server 2008 & IIS7, I found that using Vista simplified development. 

First, Vista uses IIS7 (which is the version on Server 2008) and it understands the web.config files generated by Visual Studio 2008.  I can also configure those web.config files once in one place in the file, unlike developing on XP where you have to configure the same thing in several places in the file.  Yes, UAC blows, but you can turn it off and I have had no problems using it.  I’m not advocating that you switch from XP if you want to develop services to run on Windows Server 2008, I’m just passing along that I found with Vista I created a less error prone development environment.

One last word on environment.  While you will be able to do everything in this series of articles on one machine, it will work out better for you in the long run if you have an Active Directory environment with at least three dedicated boxes; Web, Services, Database.  If you have limited equipment, consider creating seperate environments using Hyper-V.  Go to my recent post for help on creating and cloning Hyper-V environments. 

I really want to emphasize that it is in your interest to invest the sweat in creating seperate environments to run the examples in this series.  The reason is that a lot happens by default when you run everything on a single box and you’ll never realize it until you begin to move things around, and by then you’ll have to spend an undetermined amount of time to backtrack to uncover your mistakes.  Also, nobody is really going to be running this stuff on a single machine in a production environment anyway, so you might as well get used to it right off of the bat.  If you understand what the network requires to support WCF you’ll be more valuable to your company and customers.  

Before finishing this introduction, some thoughts on the Web Client Software Factory (WCSF).  This tool will allow you to code WCF services using a visual designer in Visual Studio.   One of its strengths is that it forces a particular format on project directory structure which can be advantagous since everyone on the team will be forced to structure their work the same way.   I began working in WCF using this tool, and I have to say it was a very confusing time for me as took a lot of effort to understand where the tool left off and WCF began; it was unnecessairly complex.

Furtheremore, once you start a project in the tool and need to make changes, you must go back and make them through the designer.  There are some other very severe side effects to.  One is that the tool will create directory and filenames that will break Visual Studio and this goes double if you are using Team Foundation Server.  Having outlined some of my concerns, you have to that creating such a tool is a huge accomplishment, and although this tool is just in its beginning stages, over time I am certian refinements will be introduced smoothing out some of its early difficulties.

In my mind it is best to start out simply and do everything manually so you get a clear understanding of what you need to do to support WCF services.

Next up – A Practical Architecture for WCF – Part 2 which will demonstrate the creation of services.

Advertisements

Highly Recommended WCF learning Resources


One of the most valuable resources from my point of view is the author and lecturer Michele Leroux Bustamante.  She has written a book published by O’Reilly called Learning WCF that is really a great step by step and practical approach to understanding the details and implications of WCF. 

She will start with a high level concept and drill down through to source code to illustrate her point.  And, because it is a learning experience, the code is in context with enough to help you implement it.  I am mentioning this because a lot of the books I have read on WCF are basically concepts mapped to islands of code, but nothing at a practical level to help me to tie them together.

One note about the book.  There is a new chapter out that covers Visual Studio 2008 and .NET 3.5, but unfortunately, there is a chance when you order online, you are not always garuanteed to get the second release.  I bought the first release last year and wanted the second release and ordered from Amazon and they still sent me the first release.  However, Michele says that really the only difference is chapter one and she did a deal with her publisher to provide that chapter in PDF form on her blog.  The link is: http://www.thatindigogirl.com/downloads/LearningWCFChapter01VS2008.pdf.

Additionally she has done a 15 part lecture series on WCF published through Microsoft’s Webcast series.   These lectures are downloadable and really very well worth the time.  The link for the WCF Webcast series is: http://agarwalmk.spaces.live.com/blog/cns!780CD8FB86EF8F7C!14966.entry?wa=wsignin1.0&sa=16708577.

I am revising this post to include several other books I found really helpful along the way:

  1. Programming WCF by Juval Lowy – publisher O’Reilly
  2. Pro WCF by Chris Peiris and Dennis Mulder – publisher APress
  3. Essential Windows Communication Foundation for .NET 3.5 by Steve Maine – publisher Addison Wesley

Maine’s Essential Windows Communication Foundation was the hardest book for me to understand at the beginning because he does not take a cookbook but a conceptual approach.  However the more I learned, the more I began gravitating to his book.  I really like it, however I have gotten a lot out of all of the books.

Just as an FYI, in a related post, I am writing a series of articles on a practical WCF architecture. The first post is here.

%d bloggers like this: