Hosting WCF Service in Windows Server AppFabric
Posted by: Suprotim Agarwal ,
on 11/12/2011,
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.
This article has been editorially reviewed by Suprotim Agarwal.
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!
Was this article worth reading? Share it with fellow developers too. Thanks!
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