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
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,
- Process protocol handlers.
- 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',
Step 2: A window will appear. From the left hand side of the window click the option
'Turn Windows feature on or off'.
Step 3: From the 'Windows Features' window check the option 'Windows communication Foundation Non-HTTP Activation'.
Step 4: Then finally click OK.
Step 5: For creating web application, right click on default website item and click Add Application.
Step 6: A window will appear. Enter the application name and choose the path. Finally click OK button.
Step 7: Select the application name and click the
Advanced Settings from right hand side. And a window will appear like this.
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.
- [ServiceContract]
- public interface IService1
- {
-
- [OperationContract]
- string GetData(int value);
-
- [OperationContract]
- CompositeType GetDataUsingDataContract(CompositeType composite);
-
-
- }
-
- public class Service1: IService1
- {
- public string GetData(int value)
- {
- return string.Format("You entered: {0}", value);
- }
-
- public CompositeType GetDataUsingDataContract(CompositeType composite)
- {
- if (composite == null)
- {
- throw new ArgumentNullException("composite");
- }
- if (composite.BoolValue)
- {
- composite.StringValue += "Suffix";
- }
- return composite;
- }
- }
-
- <%@ ServiceHost Language="C#" Debug="true" Service="iisHost.Service1" CodeBehind="Service1.svc.cs" %>
Add the following configurations in Web.Config file,
- <system.serviceModel>
- <behaviors>
- <serviceBehaviors>
- <behavior name="mexBehaviour">
- <serviceMetadata httpGetEnabled="true" />
- <serviceDebug includeExceptionDetailInFaults="false" />
- </behavior>
- </serviceBehaviors>
- </behaviors>
- <services>
- <service name="iisHost.Service1" behaviorConfiguration="mexBehaviour">
-
- <endpoint address="Service1" binding="netTcpBinding" contract="iisHost.IService1">
- </endpoint>
- <host>
- <baseAddresses>
- <add baseAddress="http://localhost:8080" />
- <add baseAddress="net.tcp://localhost:8086" />
- </baseAddresses>
- </host>
- </service>
- </services>
- </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.
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,
- <system.serviceModel>
- <bindings>
- <netTcpBinding>
- <binding name="NetTcpBinding_IService1" />
- </netTcpBinding>
- </bindings>
- <client>
- <endpoint address="net.tcp://sakthi/sample/Service1.svc/Service1" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IService1" contract="HelloServerRef.IService1" name="NetTcpBinding_IService1">
- <identity>
- <servicePrincipalName value="host/sakthi" />
- </identity>
- </endpoint>
- </client>
- </system.serviceModel>
Finally implement the following code in it.
- static void Main(string[] args)
- {
-
- HelloServerRef.Service1Client client1 = new HelloServerRef.Service1Client();
- Console.WriteLine(client1.GetData(1));
-
- Console.ReadKey();
- }
Running the client will give the following output:
That’s all. Please feel free to comment, if you have any questions.