Hosting WCF Service in Windows Server AppFabric

Posted by: Suprotim Agarwal , on 11/12/2011, in Category ASP.NET
Views: 145861
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.

image

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

image

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:

AppFabric

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:

clip_image010

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:

clip_image024

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:

clip_image026

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.
Give me a +1 if you think it was a good article. Thanks!
Recommended Articles
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.

Suprotim is the founder and primary contributor to DotNetCurry, SQLServerCurry and DevCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal


Page copy protected against web site content infringement by Copyscape


User Feedback
Comment posted by vishal yadav on Tuesday, December 13, 2011 12:35 AM
very nice article .
very helpful for beginner.
thanks
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...

Post your comment
Name:  
E-mail: (Will not be displayed)
Comment:
Insert Cancel