Hosting WCF Service in Windows Server AppFabric

Posted by: Suprotim Agarwal , on 11/12/2011, in Category ASP.NET
Views: 177089
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 extends windows server to provide enhanced hosting, monitoring caching capabilities especially for WCF middle tier services and web applications. This is an extension to the IIS Web server (version 7) and requires .NET Framework 4.0. It provides features like Hosting Services, tools to easy deploy, configure and monitor WCF services and Workflow Services.

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:
  • Windows Server 2008 32 or 64 Bit. Or Windows 7 32 or 64 bit.
  • IIS 7.x
  • Sql Server 2008 (R2 is better).
  • MS.NET 4.0
While installing the AppFabric,  you need to have Admin rights. You can download Windows Server AppFabric from here (Please choose the correct installable.)

After installing AppFabric, you need to run the configuration wizard for monitoring and persistence as below.

AppFabric Wizard

Create a Web Site in IIS 7 targeted to .NET 4.0. You can find similar steps for creating Web Site on IIS 7 using the link below:

Hosting WCF 4.0 Service on IIS 7.5 with SSL (Just ignore the SSL settings, rest remains the same)
Creating WCF Service to be Hosted in IIS 7 and Monitoring using AppFabric

Step 1: Open VS2010 and create a WCF Service Application. Rename IService1.cs to IService.cs and Service1.Svc to Service.svc. Open IService.cs and add the below ServiceContract and DataContract.


Step 2: Open Service.svc.cs and add the following code in it:


Step 3: Change the Service.svc in Markup as below:

<%@ ServiceHost Language="C#" Debug="true" Service="WCF_DbService.Service" CodeBehind="Service.svc.cs" %>

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:

AppFabric Deploy

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

AppFabric Package

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

Import App Package

The application path is as below:


The web application gets created in IIS:

App Fabric 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:

WCF Service

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:

WCF test client

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

WCF Endpoint address

You will get the service endpoint information as shown below:

WCF Endpoint address

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

WCF Endpoint address

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:

track events

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:

AppFabric tracked events

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

This article has been editorially reviewed by Suprotim Agarwal.

Absolutely Awesome Book on C# and .NET

C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.

We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).

Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.

Click here to Explore the Table of Contents or Download Sample Chapters!

What Others Are Reading!
Was this article worth reading? Share it with fellow developers too. Thanks!
Share on LinkedIn
Share on Google+

Suprotim Agarwal, MCSD, MCAD, MCDBA, MCSE, is the founder of DotNetCurry, DNC Magazine for Developers, SQLServerCurry and DevCurry. He has also authored a couple of books 51 Recipes using jQuery with ASP.NET Controls and The Absolutely Awesome jQuery CookBook.

Suprotim has received the prestigious Microsoft MVP award for Sixteen consecutive years. In a professional capacity, he is the CEO of A2Z Knowledge Visuals Pvt Ltd, a digital group that offers Digital Marketing and Branding services to businesses, both in a start-up and enterprise environment.

Get in touch with him on Twitter @suprotimagarwal or at LinkedIn

Page copy protected against web site content infringement 	by Copyscape

Feedback - Leave us some adulation, criticism and everything in between!
Comment posted by vishal yadav on Tuesday, December 13, 2011 12:35 AM
very nice article .
very helpful for beginner.
Comment posted by Laxmikant Patil on Wednesday, December 21, 2011 9:04 PM
Nice Article.. expecting few more features for appfabric monitoring from you in another article.
Comment posted by swapnil surve on Thursday, May 30, 2013 6:09 AM
Very Nice Article.
wants to know what if I deploy my WCF service on window service. Is there any way we can get something like this to monitor our service
Comment posted by Anbu on Tuesday, July 2, 2013 4:00 AM
+1 Thanks...
Comment posted by Ashekur Rahman on Thursday, May 22, 2014 9:44 AM
I cannot see the log. When I am trying to configure hosting services. I saw a warning "Monitoring is not configured". How to solve?