Hands-on lab: Web Service Software Factory
Welcome to the hands-on lab for the Web Service Software Factory (also known as the Service Factory). The Service Factory is a collection of guidance that helps you build high quality services in a very consistent way with less effort. The various forms of
guidance it contains are:
- Written guidance (patterns and how to topics for example)
- Reference Implementations (realistic sample applications)
- Application blocks (reusable components)
- Guidance packages (automation from within Visual Studio)
The purpose of this lab is to help you become familiar with the guidance and automation facilities within the Service Factory by walking you through the process of implementing a service for a particular scenario. It is not necessary to accomplish all of these
activities for each service you build and the Service Factory doesn’t contain guidance across all aspects of building services. However, this lab and the associated scenario were designed to cover most of Service Factory’s capabilities.
Coho Winery is a wine retailer and distributor in the northwest of the United States. Coho has established relationships with many of the local wineries throughout the Columbia Valley and offers a wine club their customers can join. Members of the club will
receive a bottle of wine per month based on their preferences for the duration of their membership.
As an added value to their customers, Coho regularly holds free wine tasting and rating events. Customers do not have to be club members to attend the tasting events. Therefore, Coho must track these types of customers independently. The following database
diagram represents the existing data model Coho currently has. The distinction between normal members and club members is evident.
Figure 1: Coho Winery's Data Model
This lab will walk you through the process of establishing the Web service to handle club memberships. Specifically, the lab walks through the implementation of the operation that adds new club members. This implementation involves the service interface, all
of the necessary business logic, and the data access logic. Much of this code and configuration is generated by the guidance packages, but because the lab aims to be reasonably realistic, there is a fair amount of manual coding as well.
The following two diagrams illustrate the domain model and information model the lab will ultimately build.
Figure 2: Coho Winery's Domain Model
Figure 3: Coho Winery's Information Model
It might be a good idea to refer back these diagrams throughout the completion of the lab if they will add clarity to the exercises.
Completing the Lab
The exercises have been designed for you to complete them in any order you choose. Of course the most straight forward and recommended approach would be to complete them in order. However, if you are unable to do so, you may start from any incomplete exercise
you chose. This is possible because the incomplete and completed solutions are provided for each exercise. For example, the incomplete solution for exercise 5 is the same as the completed solution for exercise 4.
This lab is divided into the following exercises:
The following exercises are only in the WCF hands-on lab
- Exercise 0 – Setup Lab Environment: At the end of this document, this exercise will help you ensure you have the prerequisites in place and the database is configured correctly.
- Exercise 1 – Create Solution Structure: This exercise describes how the project and solution structure is created and configured for the Coho service.
- Exercise 2 – Create Data Types: Data types represent the constructs that are reusable across multiple operations and potentially multiple services.
- Exercise 3 – Create Message Types: Message types are specific to the operation they are defined for and are composed of primitive types and the data types we create in exercise 3.
- Exercise 4 – Create Service Operations: Messages represent part of the service’s contract. These operations represent the other part and use the data and message types already defined.
- Exercise 5 – Create Business Entities: Business entities make up the domain model of the business logic layer. Given a complete data model (in the database) we can generate many of these.
- Exercise 6 – Translate Between Messages and Business Entities: This translation layer represents the very minimalist and explicit coupling between the service interface and business logic layer. This exercise will also implement the service interface,
invoke the translators, and call the appropriate business actions.
- Exercise 7 – Create CRUD Stored Procedures: Assuming these don’t already exist, we can generate them from the existing database entities (the data model).
- Exercise 8 – Create Data Repository Classes: These are the classes that interact with the database. This is effectively the data access logic that returns business entities to the business logic.
- Exercise 9 – Invoke Data Access Layer: This exercise describes how to write the business logic to invoke the data repository classes.
- Exercise 10 – Wire up Client and Test Service: This exercise describes how to expose the service and add a reference to it from the provided client application.
- Exercise 11 – Modifying the WCF Guidance Package: This exercise illustrates how to modify An existing guidance package by adding Exception Shielding to the service contract project.
- Exercise 12 – Server-Side Message Validation: This exercise adds message validation to the logic of the service.
- Exercise 13 – Extending WCF Semantic Code Analysis: This exercise walks through the process of adding an additional semantic code analysis rule to the existing rules provides in Service Factory.
- Exercise 14 – WCF to ASMX Interoperability: This exercise changes the Service Factory Reference Implementation to illustrate how to call an ASMX service using a WCF consumer.
Helper Source Code
Throughout the exercises, there are tasks which must be completed and either take an unfortunate amount of time to type in or are not specific to building services (for example, the business logic). In these instances, the source code has been provided for
you. You will find this code in the HelperCode folder and the file will be named according to the step being accomplished in the exercise.
Many of the steps in the exercises involve completing a screen in a wizard-based interface. The steps are meant to contain are enough information to complete the step. However, if you find some of the instructions unclear, you can find a screenshot of the wizard
screen (after the step has been completed) in the ScreenShots folder. The image will be named according to the step it is describing.
Setting up the Lab Environment
Each participant’s computer should have the following installed (in order):
Create the Coho Database
- If you are using SQL Server 2005 Express Edition and you would like to create the Coho database in the
SqlExpress instance on the local machine, skip to step 4.
- Open a command prompt and navigate to the root folder of the lab.
- Execute the CreateCohoDatabase.cmd while passing in the name of the
machine\instance the CohoWinery database should be created in.
- When “Finished!” appears in the command window, the database is installed. You may now close the command window.