At this point, we have specified WCF as the technology for the service implementation, but we still haven't generated any code. The Solution Explorer only has few nodes, as shown in the following image:
The solution item ProjectMapping.xml is an empty file, with no project included. Next, we will create the framework projects for the service, and generate lots of source code from the models.
Before we can generate the source code from the models, we need to create a few projects, and add them to the solution. Follow these steps to create all of the required projects:
Service Factory will generate ten projects according to the Service Contract and Data Contract Models, including the Business Entities projects, Business Logic projects, Data Access Layer projects, Data Contracts projects, Fault Contracts projects, Message Contract projects, Service Contracts projects, and Service Implementation projects. The Solution Explorer is now full of projects, as shown in the following image:
Inside each project, the Service Factory has added the required references, and some configuration files. For example, the ServiceContracts project has references to MyWCF.EasyNorthwind.DataContracts, MyWCF.EasyNorthwind.FaultContracts, and MyWCF.EasyNorthwind.MessageContracts, as well as System.Runtime.Serialization, and System.ServiceModel.
It has also generated a hosting application and a testing client for the service, which we will customize later.
Now that we have all of the projects generated, we can tell the Service and Data Contract Models which project they should link to.
The project mapping table, MyWCF.EasyNorthwind, is an element within the ProjectMapping.xml file. This element was added to the project mapping XML file when we created the projects in the previous section. It maps from solution projects to a set of predefined roles. So, after we specify the Project Mapping Table of the service contract model to this element, and later generate the code, the Service Factory will know which project the generated artifacts should go to.
At this point, we have finished modeling our service contracts, and have also specified technologies for the service implementation. Both models should now be valid.
To see the validation results, right-click on an empty space in the design pane for either of the contract models, select Validate All from the context menu, and you will see the following messages in the output window:
------ Validation started: Model elements validated: 17 ------
======== Validation complete: 0 errors, 0 warnings, 0 information messages =======
If you have tried to validate any model prior to this point, you may have seen a few validation errors, such as "Project Mapping Table property is empty".
You can compile and build the solution successfully now, though it is not yet complete (actually, there is no source code to build in the solution at this point).
The Service Factory has now generated ten projects, but it hasn't generated any source code from the Service and Data Contract Models. You can build and run it now, but it won't be functioning as a WCF service. In this section, we will ask Service Factory to generate all of the necessary source code for the service.
The Factory will generate source code for all of the defined Data contracts and Fault contracts in the model.
The Factory will generate source code for all of the service interfaces, service implementations, operations, messages, and any other necessary files.
You may see a warning message saying that a custom tool failed. Do not worry about this warning. It's ok for us to move on.
You can also right-click on any shape in the Contract Model diagrams, and select Generate Code for that shape only. This feature is helpful if, later on, you need to change some of the models.
Now, open a project under the Service Interface folder, such as MyWCF.EasyNorthwind.DataContracts. You will see the generated files under the GeneratedCode folder.
This will generate the source code for all of the service interface projects, including the Data Contracts project, Fault Contracts project, Message Contracts project, Service Contracts project, and Service Implementation projects. If you check the business entities project, the business logic project, or the data access project, you will find that no source code has been generated yet. There is no code generated for the test client, or the host application either. So the EasyNorthwind solution is still not a complete WCF service. In the next chapter, we will complete it by generating and customizing all of the other projects.
Build the solution again. There should be no errors.