Windows Communication Foundation Service also known as WCF Service provides us an optimal way in creating Services. It can be hosted in a variety of ways (as explained by below diagram) including IIS, Console Application, .NET application or can be hosted as Windows Service. So why should we go for WAS hosting i.e. Windows Activation Service. In this WCF Tutorial, we are going to learn that what is WAS?, how to host in it and the benefits of using it.
Note: The WCF service hosted completely in WAS, works similarly like legacy Web Service (ASMX).
Create a simple WCF Service
- We are really going to build a very simple WCF service, I will use Visual studio 2010 & IIS 7.5 throughout the lesson. Open Visual Studio -> New project -> WCF -> Select WCF Application Service.
- Once the application is open, you can see WCF example methods auto generated. We can just make use of it. It’s quite simple.
- Run the WCF application or hit F5, now you can see WCF Test Client pops out, asking for the input values. You can make sure your application is working correctly.
- Now let us try initiating in browser via HTTP protocol. We need to modify the Web.config file accordingly.
- Locate the URL pointing to the .svc file that we created now.
- Cool, we got our service live, kindly note: All these are been handled by IIS server where it instantly host our service application to the random port. By default as we discussed it only supports HTTP protocol. Further, you can follow here if interested to create and work with HTTP Services.
Now let us try mapping our application to a Non-HTTP protocol, modify the bindings of Web.Config as below.
Run the WCF application or hit F5. As expected our IIS doesn’t understand the protocol and says that it “Could not find a base address….”
We can resolve this by setting up Windows Activiation Service (WAS) and this is the main objective for this WCF Tutorial.
Install and Set up WAS
- Add a Virtual directory and map our application from IIS directly so that we can play around with Protocol bindings.
- To install WAS, go to Control Panel -> Program & Features – > Turn On & Off Windows feature -> Microsoft .NET Framework 3.5.1 -> Check on the Windows Communication Foundation Non-HTTP Activation. This is the WAS which is OFF in default.
- Once, we turn on the Non-HTTP activation, go to the IIS -> Our Hosted Service -> Advanced Settings -> Add the net.tcp protocols under Enabled Protocols.
Note: We can as many protocols as Comma Separated Values.
- Next, we have to set the binding value to net.tcp protocol, to do that go to IIS -> Our Hosted Service -> Site Bindings -> Add -> Type as net.tcp and Binding information as “<Port Number>:*”.
- Finally, try navigating our browser to the same URL as we tried before.
That’s it, we just hosted our WCF Service application in a Windows Activation Service type. Play around with it. You can consume the service by mapping the endpoint in your application as usual. Now let us see the benefits of hosting our application in WAS.
Benefits of Hosting in WAS
Hosting in WAS (Windows Activation Service) has many advantages like Multiple Protocol Support, Reliability etc. Lets discuss briefly few of the most important ones.
- Low Overhead: Being a windows component it is completely separate from IIS server host and relieved from Overhead associated with hosting server.
- Supports multiple protocols: As with IIS (Internet Information Services) by default HTTP is supported only and thus we enabled it by switching on WAS and triggered required protocols.
- Health monitoring: Hosting in WAS provides us enough flexibility in monitoring the health of each application service.
- Memory leak avoidance: WAS Recycling feature helps us to control the memory leaks and thus improves the efficiency.
- Configurations: The configuration can entirely controlled via config files such as web.config or app.config. For instance the directory listing setting true enables user to access the folder and files.
Thus WCF service hosting in WAS environment has more benefits and improves the stability of the service. Clients can rely on the service more than any other hosting technique. You must have learnt something new from this WCF Service Hosting Tutorial. Waiting for your feedback and comments.
Happy WCF Programming!