Hosting WCF Service in Windows Server AppFabric
Posted by: Suprotim Agarwal
in Category ASP.NET
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:
After installing AppFabric, you need to run the configuration wizard for monitoring and persistence as below.
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:
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:
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 Windows Server AppFabric is a must have for an administrator to monitor WCF and WF Services, for effective application management.
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 pre-order of The Absolutely Awesome Book on C# and .NET. This is a concise technical eBook and will be available in PDF, ePub, and mobi.
Organized around concepts, this eBook aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core. Use these concepts in your next .NET Project or to crack your next .NET Interview.
Click here to Pre-Order this eBook at a Discounted Price!