Now that we have the service ready, we need a host application to host it, and a client application to test it. But if you open the Host
or Client
folders in the solution, you will see that they are not completed. We have to do some extra work to make them work.
Service Factory does not use WCF Service Host to host the service. Instead, it chooses to use the ASP.NET Development Server to host the service. It also creates a separate host application, so that the service projects and the host application are stored in separate folders.
The test client Service Factory created for us is a Windows application, with a text box and a Execute button in it.
Service Factory also supplies a host model that we can use to model the host and client applications. Next, we will use this model to generate the basic host and client applications. We will host the EasyNorthwind WCF service in this new host application, and test it with the new test client.
Follow these steps to model the host application:
http://EasyNorthwind.MyWCF.MyCompany.com
as the XML namespaceNow, the Host Model diagram should open up on your screen. As this model is empty, we can't do anything with this diagram. We first have to add a host application to the model to enable it.
Follow these steps to add a host application to this host model:
Now that we have the host application created, and the service reference added, we need to define an endpoint for it. Later, in this chapter, the test client will communicate with this endpoint to test the service.
Now that we have finished modeling the host application, we will generate the source code for the host application from this host model.
But before we can generate the source code for the host application, we need to validate this host model. You can do this from the Host Explorer, or from within the Host Model diagram.
ProductServiceRef.svc
, populate the configuration file web.config
, and copy all of the service related assemblies to the bin
directory. All of these files are under the folder D:SOAwithWCFandLINQProjectsEasyNorthwindMyWCF.EasyNorthwindTestsMyWCF.EasyNorthwind.Host
.The host application has now been generated. Next, we will create the test client application. We will use this test client to test the service.
As with the host application, Service Factory also allows us to create a test client from the host model. First, we need to follow these steps to add a client application to the host model.
The final Host Explorer looks like this:
We have added the test client to the host model and added a reference to the endpoint of the service. Next, we will generate the source code for the test client from this model.
In this section, we will use Service Factory to generate the proxy classes of the WCF service for the client application. In one of the previous chapters, we used the tool SvcUtil.exe
to generate the proxy files manually. Here, Service Factory will do this job for us. After we have generated the proxy files, we will customize the test client to call the service in the next section.
Follow the steps below to generate the proxy files:
folder
, and select Build Web Site from the context menu. Right-click on it again, and select View in Browser. The ASP.NET Development Server will be started, and a browser will open to show all of the files under the virtual folder MyWCF.EasyNorthwind.Host.This will generate the service reference file, EasyNorthwindProxy.cs
, and populate the configuration file, app.config
. These two files are under the folder: D:SOAwithWCFandLINQProjectsEasyNorthwindMyWCF.EasyNorthwindTestsMyWCF.EasyNorthwind.Client
.
If you haven't started the host application, when you click Next, you will get an error saying "can't download metadata".
You can now build the client project, to make sure there is no build error.