Host The WCF In Windows Process Activation Service

Let us see what is WAS, why we need to use it, and how to enable WAS in IIS.

What is WAS

It is a new process-activation service and generalized in the IIS 7 and above version. This feature used to work with non-HTTP transport protocol through the IIS like TCP, Named Pipe, etc. The Listener Adaptor windows service is used here to receive the messages from the client on specific protocol and communicate with WAS to route the incoming messages tothe  correct worker process.

Why we use WAS

This question may arise for you: Why do we need to use WAS compared to other things like self host? Because, if we do like self host, we need to manage the service life cycle and idle time and need to write some code for these things. If we use the WAS hosting, the entire responsibility will be taken by the IIS. It will manage all things like hosting process, idle time management, etc. So the reason we will move to WAS is hosting.

WAS Component

WAS Component

Listener Adaptor

It is a windows service that receives messages on specific network protocols and communicates with WAS to route incoming messages to the correct worker process.

Application manager

It manages the creation and lifetime of application domains that host applications within the worker process.

Protocol Handler

Protocol-specific components that run in the worker process and manage communication between the worker process and the individual listener adapters.

The following two types of protocol handlers exist in WAS,
  1. Process protocol handlers.
  2. AppDomain protocol handlers.
Steps to configure the WAS in IIS

I think it is enough for theoretical explanation about WAS. We will see how to configure it in IIS.

Step 1: Open the 'Control Panel' and choose the 'Programs and features',

panel
Step 2: A window will appear. From the left hand side of the window click the option 'Turn Windows feature on or off'.windows feature
 

Step 3: From the 'Windows Features' window check the option 'Windows communication Foundation Non-HTTP Activation'.

windows

Step 4: Then finally click OK.

Step 5: For creating web application, right click on default website item and click Add Application.

Application
 
Step 6: A window will appear. Enter the application name and choose the path. Finally click OK button.

button

Step 7: Select the application name and click the Advanced Settings from right hand side. And a window will appear like this.

app

Step 8: Here, I am going to enable net TCP binding. So enter the text in Enabled protocols as http, net.tcp and click OK.

Now, our IIS configuration is over. We need to develop the application to host it. For this, I will use the following code generated by visual studio while creating WCF application.
  1. [ServiceContract]  
  2. public interface IService1  
  3. {  
  4.   
  5.     [OperationContract]  
  6.     string GetData(int value);  
  7.   
  8.     [OperationContract]  
  9.     CompositeType GetDataUsingDataContract(CompositeType composite);  
  10.   
  11.     // TODO: Add your service operations here  
  12. }  
  13.   
  14. public class Service1: IService1   
  15. {  
  16.     public string GetData(int value)   
  17.     {  
  18.         return string.Format("You entered: {0}", value);  
  19.     }  
  20.   
  21.     public CompositeType GetDataUsingDataContract(CompositeType composite)  
  22.     {  
  23.         if (composite == null)   
  24.         {  
  25.             throw new ArgumentNullException("composite");  
  26.         }  
  27.         if (composite.BoolValue)  
  28.         {  
  29.             composite.StringValue += "Suffix";  
  30.         }  
  31.         return composite;  
  32.     }  
  33. }  
  34.   
  35. <%@ ServiceHost Language="C#" Debug="true" Service="iisHost.Service1" CodeBehind="Service1.svc.cs" %>  
Add the following configurations in Web.Config file,
  1. <system.serviceModel>  
  2.     <behaviors>  
  3.         <serviceBehaviors>  
  4.             <behavior name="mexBehaviour">  
  5.                 <serviceMetadata httpGetEnabled="true" />  
  6.                 <serviceDebug includeExceptionDetailInFaults="false" />  
  7.             </behavior>  
  8.         </serviceBehaviors>  
  9.     </behaviors>  
  10.     <services>  
  11.         <service name="iisHost.Service1" behaviorConfiguration="mexBehaviour">  
  12.   
  13.             <endpoint address="Service1" binding="netTcpBinding" contract="iisHost.IService1">  
  14.             </endpoint>  
  15.             <host>  
  16.                 <baseAddresses>  
  17.                     <add baseAddress="http://localhost:8080" />  
  18.                     <add baseAddress="net.tcp://localhost:8086" />  
  19.                 </baseAddresses>  
  20.             </host>  
  21.         </service>  
  22.     </services>  
  23. </system.serviceModel>  
Now, the implementation and the configuration is over. So map the service path with IIS application and browser using the URL.
The output will be like this.
 
output
 
To capture the service create the client application and add service reference to it. If we see the client’s configuration, it will be like this,
  1. <system.serviceModel>  
  2.     <bindings>  
  3.         <netTcpBinding>  
  4.             <binding name="NetTcpBinding_IService1" />  
  5.         </netTcpBinding>  
  6.     </bindings>  
  7.     <client>  
  8.         <endpoint address="net.tcp://sakthi/sample/Service1.svc/Service1" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IService1" contract="HelloServerRef.IService1" name="NetTcpBinding_IService1">  
  9.             <identity>  
  10.                 <servicePrincipalName value="host/sakthi" />  
  11.             </identity>  
  12.         </endpoint>  
  13.     </client>  
  14. </system.serviceModel>  
Finally implement the following code in it.
  1. static void Main(string[] args)  
  2. {  
  3.   
  4.     HelloServerRef.Service1Client client1 = new HelloServerRef.Service1Client();  
  5.     Console.WriteLine(client1.GetData(1));  
  6.   
  7.     Console.ReadKey();  
  8. }  
Running the client will give the following output:

output
 
That’s all. Please feel free to comment, if you have any questions.


Similar Articles