Hosting WCF Service in Windows Server AppFabric

Abstract: In this article, we will see how to use the Windows Server AppFabric to monitor WCF and WF Services, for effective application management.

If you are developing distributed service oriented applications using Microsoft.NET, then the Windows Communication Foundation (WCF) framework is strongly recommended. WCF is a great choice for applications that communicate over various protocols e.g., HTTP, TCP, MSMQ etc. and also need a secure communication mechanism.

One of the major challenges a developer faces is how to monitor and track a WCF service, once the WCF service is hosted in the hosting environment. Once the application is deployed in the production environment,it becomes essential to track how the WCF service is performing e.g. while making a call to WCF if any exception occurs then how do we know about it and so on. To make such things possible, we have been provided a new hosting environment that is Windows Server AppFabric.

Windows Server AppFabric provides two runtime databases - Monitoring Schema and Persistence Schema. Monitoring Schema provides capabilities to monitor activities of the WCF and WF services hosted. Persistence Schema provides capabilities to save state of the Workflow running. After installing the AppFabric, you need to configure it for Monitoring and Persistence and while doing this, the required database gets created. Here you need to make sure that you meet the following system requirements:

Step 4: Right-Click on the WCF Application and go to properties, Select Package/Publish Web, make sure that ‘Create a Deployment package as a Zip file’. This will specify the location of the Zip file where the deployment package is stored. Also specify the Web Site name on the destination host server as below:

Step 5: Open IIS, right click on the Web Site and Select Deploy > Import Application as shown below:

Step 6: Select the package path as below and click Next:

Step 7: The Next step shows the Package contents, keep the selection as it is and click Next:

The application path is as below:

The web application gets created in IIS:

The marked area represents the Web Application created by the name of ‘WCF_DbService_deploy_new’ and the AppFabric Dashboard.

Step 8: Open the WCF Service in the browser by browsing the Service.Svc file from the ‘Content View’. The result will be as below:

Step 9: Go to the .NET Command Prompt and type the following in the Command-line - ‘WCFTestClient’. This will provide the default Client Testing as shown below:

Step 10: Right click on the ‘My Service Projects’, and type the EndPoint address as shown below:

You will get the service endpoint information as shown below:

Step 11: Double Click the ‘GetDepartments()’ method and you will get the display as shown below:

and enter the name of the Database e.g. ‘Company’ and click on invoke, the result will be displayed in the Response part as shown below:

Step 12: Since, the WCF service is hosted in IIS and AppFabric is configured for IIS, select the application you have created and then click on the ‘AppFAbric DashBoard’. The result will be as below:

The RED marked area represents the WCF service monitoring statistics i.e Completed calls and Errors, if any. If you click on ‘Completed’, the Track Events windows gets displayed. This window provides the summary of the calls as below:

While testing the call using the ‘WCFTestClient’, if you enter any invalid value, an exception will be occur and in the AppFabric, the error summary will be displayed, as below:

Conclusion: The WindowsServerAppFabric is a must have for an administrator to monitor WCF and WF Services, for effective application management.

Suprotim Agarwal, ASP.NET Architecture MVP, MCSD, MCAD, MCDBA, MCSE, is the CEO of A2Z Knowledge Visuals Pvt. He primarily works as an Architect Consultant and provides consultancy on how to design and develop .NET centric database solutions.