Share via


WCF: IIS hosting of net.tcp/ net.pipe services + metadata

A lot of time, customers around the globe question how best WCF services (running on net.tcp/ net.pipe protocol) can be hosted on IIS.

The popular bindings for the same are:

  -  netTcpBinding

  -  netNamedPipeBinding

As a naïve developer it is possible that service may not be hosted properly unless the configuration steps are followed properly.

I am sharing sample code/ configuration/ screenshots on this behalf.

 

Service Design 

1. Code 

namespace WcfService1

{

    [ServiceContract]

    public interface IService1

    {

        [OperationContract]

        string GetData(int value);

    }

}

namespace WcfService1

{    

    public class Service1 : IService1

    {

        public string GetData(int value)

        {

            return string.Format("You entered: {0}", value);

        }

    }

}

 

2. Configuration 

<system.serviceModel>

    <behaviors>

      <serviceBehaviors>

        <behavior name="netBehavior">

          <serviceMetadata httpGetEnabled ="true"/>

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

      </serviceBehaviors>

    </behaviors>

    <bindings>

      <netTcpBinding>

        <binding name="netBinding">

          <security mode="None"/>

        </binding>

      </netTcpBinding>

      <netNamedPipeBinding>

        <binding name="pipeBinding">

          <security mode="None"/>

        </binding>

      </netNamedPipeBinding>

    </bindings>

    <services>

      <service name="WcfService1.Service1" behaviorConfiguration="netBehavior">

        <endpoint address=""   binding="basicHttpBinding"  contract="WcfService1.IService1" />

        <endpoint address=""  binding="netTcpBinding" bindingConfiguration="netBinding"  contract="WcfService1.IService1"   />

        <endpoint address="tmex" binding="mexTcpBinding" contract="IMetadataExchange" />

        <endpoint address=""  binding="netNamedPipeBinding" bindingConfiguration="pipeBinding"  contract="WcfService1.IService1"   />

        <endpoint address="pmex" binding="mexNamedPipeBinding" contract="IMetadataExchange" />

      </service>

    </services>

  </system.serviceModel>

 

IIS hosting

a)      Deploy the service in IIS virtual directory

b)      Go to the site > Right click > Edit Bindings

               

c)       Go to the deployed application under the site

                         

d)      Here application is netPipeService1.

                    Right click > manage application > Advanced settings                              

e)      Update Enabled Protocols like the following:

                        

f)       Restart the application pool

 

Since we have an endpoint available over http, we should be able to browse the service component.

                   

 

Let’s go to the wsdl document. The <wsdl:service> content appears as the following:

              

 We can see the 3 highlighted endpoints now on the service metadata.

 

Client

Now, client application can create the proxy classes by 3 options.

Option 1

Add service reference with http endpoint:

               

Option 2

Add service reference with mex/tcp endpoint:

              

Option 3

Add service reference with mex/pipe endpoint:

           

 

In real time, it could happen you may have either of the bindings to play with. I would recommend to start from small and slowly increase breadth for other bindings.

 

 

I hope this helps!