Click here to Skip to main content
15,888,610 members
Articles / Programming Languages / C#

Hosting WCF Service in WAS Simplified

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
30 Jul 2015CPOL4 min read 7.4K   4   1  
Hosting WCF service in WAS simplified

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 the 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 what WAS is, how to host in it and the benefits of using it.

WCF Hosting Options

.NET introduced WCF technology from version 3.0 and it provides a huge stack of protocol supports such as HTTP, TCP, MSMQ, IPC, and WCF REST based, etc. Initially, while Microsoft introduced IIS 6.0, the WCF service hosting in IIS only supported HTTP protocol. Later, WCF shipped with Windows Vista where it supported all other protocols such as TCP, MSMQ, and Named Pipes, etc. This enables a convenient way of implementing WCF service without much programming.

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.

    WCF Service Application

  • Once the application is open, you can see WCF example methods auto generated. We can just make use of it. It’s quite simple.

    WCF Example

  • 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.

    WCF Test Client

  • Now let us try initiating in browser via HTTP protocol. We need to modify the Web.config file accordingly.

    Web.Config in WCF Service

  • Locate the URL pointing to the .svc file that we created now.

    WCF Service Running

  • Cool, we got our service live, kindly note: All these are being handled by IIS server where it instantly hosts our service application to the random port. By default, as we discussed, it only supports HTTP protocol. Further, you can follow here if you are interested in creating and working with HTTP Services.

Now let us try mapping our application to a Non-HTTP protocol, modify the bindings of Web.Config as below:

Non-Http Protocol

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….”

WCF Tutorial - 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.

    WCF Web Service

  • 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.

    WCF Non-Http Activation

  • 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 have as many protocols as Comma Separated Values.

    WCF Advanced Settings

  • 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>:*”.

    WCF Site Bindings

  • Finally, try navigating our browser to the same URL as we tried before.

    WCF Hosting in WAS

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. Let's briefly discuss 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 be entirely controlled via config files such as web.config or app.config. For instance, the directory listing setting true enables the 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.

Download Complete Source Code for this WCF Article here.

Happy WCF Programming!

Other WCF Services and Related Tutorials

The post Hosting WCF Service in WAS Simplified appeared first on WCF Tutorial.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Emaratech
United Arab Emirates United Arab Emirates
Imran Abdul Ghani has more than 10 years of experience in designing/developing enterprise level applications. He is Microsoft Certified Solution Developer for .NET(MCSD.NET) since 2005. You can reach his blogging at WCF Tutorials, Web Development, SharePoint for Dummies.

Comments and Discussions

 
-- There are no messages in this forum --