The Tampa Bay Buccaneers play the Carolina Panthers at 1pm today, and I am so frustrated with the play calling by Jon Gruden this season that I don't think I can watch the game in real-time. We have two 0-2 football teams needing a win badly, and if the Bucs didn't have home field advantage today, I would predict a win by the Panthers. I can't stop pacing around the house and mumbling to myself today, so let's talk about the Web Service Software Factory!
Sam has been mentioning the Web Service Software Factory quite a bit and using it in production, but I haven't had a lot of time for it until this past week. It is my first real introduction to the code generation and automation capabilities of the Guidance Automation Extensions and Toolkit, and I am blown away.
The Web Service Software Factory is a combination of two very impressive guidance packages:
- ASMX guidance package. This guidance package helps build the service interface, the messages the service will expose and consume, and the translators that map these messages to domain model entities.
- Data Access guidance package. This guidance package helps build business entities from and existing data model, build stored procedures from a data model, and generate the repository classes and factories that comprise the data access logic.
I decided to create web services to administer a simple, unfinished, and mythical blog engine whose database and tables have already been created:

The Web Service Software Factory will generate a number of projects in your solution for you based on nothing more than namespace information:

Data Access Guidance Package
Things start getting really interesting when you start invoking the guidance packages.
The Data Access Guidance Package is a collection of recipes, wizards, etc. that offer some pretty cool code generation capabilities based on an existing database and its set of tables. It can help generate
CRUD Stored Procedures
Business Entities for each Table
A Data Access Layer full of repositories that map stored procedures to getone, insert, update, delete CRUD methods, etc
It had me at hello :)
Generate CRUD Stored Procedures
I walk through the wizard to generate stored procedures. I am playing here, so I just pick my four tables and accept the defaults and in about a minute I have a sweet looking Blogs.sql file inserted in my data access layer project that I run against my database and get the following ( more pictures ):

I know we can get this from CodeSmith and other places, but you have to love it.
Generate Business Entities
The same 1 minute process works to generate my business entities. I select the tables, rename the plural names to singular ( you can even rename the properties so they don't have to match the column names ) in a quick wizard:

These are simple persistent ignorant business entities: Default Constructor, Fields, and their associated properties.
Generate The Repositories for my Data Access Layer
Now that I have the stored procedures and business entities created, I run another wizard that creates a repository for each table, allowing me to 1) map stored procedure to CRUD methods and 2) map stored procedure input and output parameters to business entity properties. This wizard could be made easier and faster, but again the process is simple:

These aren't repositories in the Domain-Driven Design sense, because each table has a repository, where in DDD only aggregates have a repository. I think of them as Data Access Objects.
Generate Some Business Logic to Get A Blog Post
Up to this point I have just been fighting carpal tunnel by all this mouse clicking, and haven't done any coding. The horror :)
Here is my first cut of the business logic for getting a blog post by Id.
using Boohoo.BlogAdminServices.BusinessEntities;
using Boohoo.BlogAdminServices.DataAccess;
namespace Boohoo.BlogAdminServices.BusinessLogic
{
public class GetPostAction
{
public Post Execute(int postId)
{
PostRepository postRepository = new PostRepository("Blog");
Post post = postRepository.GetPostByPostId(postId);
if (post != null)
{
CategoryRepository categoryRepository = new CategoryRepository("Blog");
CategoryCollection categories = categoryRepository.GetCategoriesByPostId(postId);
post.Categories = categories;
}
return post;
}
}
}
Conclusion
This has all been about the Data Access Guidance Package ( wait 'til we talk about the ASMX Guidance Package ), which shows you some pretty cool code generation of stored procedures, business entities, and a data access layer. It's worth checking out if just to use the code generation and learn some design patterns.
Now for that Bucs and Panthers Game...
Resources