Follow Us

Skip Navigation LinksHome > Articles > WCF > Understnading WCF 4.0 File Less Activation

Understnading WCF 4.0 File Less Activation

This article breifly explains a new feature of WCF 4.0 called File Less Activation.

By Keyur   On   Tuesday, 10 May 2011

Page Views : 6774   |   Technologies : WCF

Rating : Rated :
1
| More..
WCF 4.0 File Less Activation

That’s correct. You read the title right. You do not need the .svc file any more to host WCF service.

In this article we are going to take a look at the new WCF 4.0 feature called File Less Activation . So as the name suggest what it means is that in order for you to host WCF service in IIS you no longer need the dedicated .svc file in your application. I was really surprised when I first heard about it so here I am with a sample service running without any .svc files in it.

Creating an empty web applicaiton

The very first thing we will do is create an empty Asp .Net Web application which will host our WCF service class, yes you heard correct, the WCF service class and not the actual WCF service .svc file.

Adding a WCF service class file.

Next we add reference to the following two namespaces our application will need in order to host the WCF service.

System.ServiceModel.Activation

Next what I have done is created a service Interface called IFileLessActivation and an actual service class that implements this interface which is called FileLessActivation.cs.

Modifying the web.cofig file

Now let’s go ahead and enable the service from the config file.

		<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" >
<serviceActivations><add service="FileLessActivation.FileLessService" relativeAddress="FileLessService.svc"/>
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
	

Here is the trick. While defining the activation section of the configuration I am providing the type of the service I want to active and providing relative address which kind of an alias which tell the application that the WCF service class FileLessService will be hosted and be accessible as the FileLessService.svc. But in reality it will eliminate the need of having the actual physical .svc file for every WCF you want to expose through your application.

If you are following all the steps along let’s go ahead and run the application and you should be able to reach to your service in the traditional fashion but without have a need for physical .svc file.

As you can see from the screens hot the IMetaDataExchange is not exposed and so no Meta data WSDL is available for the operations the WCF service is providing. But if you look carefully into the configuration section I have not defined any endpoint or binding as well for my actual service! And that’s because I am using another new feature of WCF 4.0 which is known as Simplified Configuraitons where all the setting s will be enabled by the WCF infrastructure itself and we do not need to get into details of configuration.

Enabling MetaData Excahnge

And so the last step we need to do before anybody can start talking to our service is enabling the IMetaDataExcahnge endpoint into our service. Go ahead and make following changes which will enable the Meta data exchange endpoint within your application.

		<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" >
<serviceActivations>
<add service="FileLessActivation.FileLessService" relativeAddress="FileLessService.svc"/>
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
	

And now when you revisit the service you should see the wsdl is enabled for the service now.

This is a very cool and interesting feature of WCF 4.0. I have tried to demonstrate this new feature in the shortest and easiest way possible. So that’s it for now to these WCF 4.0 new features.

Thanks.


Keywords : using System.ServiceModel.Activation;

Tags : WCF 4.0 File Less Activation
Rate This Article :

Comments :

blog comments powered by Disqus
User Login
Username :
Password :
Register Login

Forgot Password


Related Articles