Chapter 8. Implementing the WCF Service with Service Factory

In the previous chapter, we modeled and generated the source code for a WCF service using Service Factory. Although the service interface code is generated based on the Contract Models, no business entity, or data access layer, or business logic layer code has been generated at all. The Modeling Edition of the Service Factory doesn't give any tool to automatically generate code for them. You may recall that with the previous version's Service Factory, you could generate business entities from a database, but this is not the case for this version.

In this chapter, we will manually add code for these projects, so that we have a completed WCF service. We will also generate the host application and test client using Service Factory, and then test the WCF service.

We will follow these steps to complete the EasyNorthwind service in this chapter:

  • Adding the business entities
  • Adding the data access class
  • Adding the business logic class
  • Translating the messages
  • Customizing the Fault contract class
  • Modifying the service interface layer to call the business logic layer
  • Modeling the host application and generating source code for the host application
  • Creating the test client
  • Testing the WCF service using the test client

Creating the business entities

First, we will create our business entities for the service. Follow these steps to add the product entity to the project:

  1. In the Solution Explorer, right-click on the MyWCF.EasyNorthwind.BusinessEntities project.
  2. Select Add | Class from the context menu.
  3. In the popped up Add New Item window, enter ProductEntity.cs as the name.
  4. Click Add.

Now, customize the ProductEntity.cs file:

  • Change it to be a public class
  • Add new members for the product entity

The final ProductEntity class file should look like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyWCF.EasyNorthwind.BusinessEntities
{
public class ProductEntity
{
public int ProductID {get; set;}
public string ProductName {get; set;}
public string QuantityPerUnit {get; set;}
public decimal UnitPrice {get; set;}
public int UnitsInStock {get; set;}
public int ReorderLevel {get; set;}
public int UnitsOnOrder {get; set;}
public bool Discontinued { get; set; }
}
}

Build the business entities project, to make sure that there is no build error.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset