In previous chapters, we created a WCF service by using LINQ to Entities in the data access layer. Next, we will apply settings so that this WCF service will be a distributed service, which means that it can participate in distributed client transactions, if there are any. Client applications will control the transaction scope and decide whether a service should commit or rollback its transaction.
In this chapter, we will first verify that the LINQNorthwind
WCF service, which we built in the previous chapter, does not support distributed transaction processing. We will then learn how to enhance this WCF service to support the distributed transaction processing and how to configure all related computers to enable the distributed transaction support. To demonstrate this, we will propagate a transaction from the client to the WCF service and verify that all sequential calls to the WCF service are within one single distributed transaction. We will also explore the multiple database support of the WCF service and discuss how to configure
Microsoft Distributed Transaction Coordinator (MSDTC) and the firewall for the distributed WCF service.
We will cover the following topics in this chapter:
DistNorthwind
WCF serviceIn this chapter, we will create a new solution based on the LINQNorthwind
solution. We will copy all of the source code from the LINQNorthwind
directory to a new directory and then customize it to suit our needs.
Follow these steps to create the new solution:
DistNorthwind
under the existing C:SOAwithWCFandLINQProjects
directory.C:SOAwithWCFandLINQProjectsLINQNorthwind
directory to the C:SOAwithWCFandLINQProjectsDistNorthwind
directory.LINQNorthwindClient
folder. We will create a new client for this solution.LINQNorthwind.sln
to DistNorthwind.sln
and also from LINQNorthwind.v11.suo
to DistNorthwind.v11.suo
.Now, we have the file structures ready for the new solution. Here we will re-use the old service to demonstrate how to plug in transaction support to an existing WCF service.
First, we need to make sure this old service in the new solution still works and we also need to make a small change to the service implementation so that we can test transaction support with it. Once we have the service up and running, we will create a new client to test this new service by using the following steps:
C:SOAWithWCFandLINQProjectsDistNorthwindDistNorthwind.sln
solution.LINQNorthwindClient
project.ProductService.cs
file in the LINQNorthwindService
project in this new solution and remove the condition check for negative price check in the UpdateProduct
method. Later we will try to update a product's price to be negative to test the distributed transaction support of WCF.If this check is not removed, when we try to update a price to be negative later in this chapter, the operation will stop right at this validation check. It won't be able to reach the DAL where LINQ to Entities will be used, and the remote database will get involved, which is the key part for a distributed transaction support test.
The following screenshot shows the final structure of the new solution DistNorthwind
:
Now, we have finished creating the solution. If you build the solution now, you should see no errors. You can set the service project as the startup project, run the program, and the output should be the same as seen in the Testing the service with the WCF Test Client section in Chapter 9, Applying LINQ to Entities to a WCF Service.