AsiaTech: Microsoft APGC Internet Developer Support Team

We focus on various troubleshooting plan and solution on IIS web platform and distributed applications

Modifying SMSvcHost.exe.config for WCF --- Some common mistakes

Modifying SMSvcHost.exe.config for WCF --- Some common mistakes

Rate This
  • Comments 5

 

Some WCF services may use net.tcp for high-performance communication. These self-hosted services can control several advanced settings on the service's transport binding element, such as ListenBacklog and MaxPendingAccepts, which govern the behavior of the underlying TCP socket used for network communication.

 

When a net.tcp binding enables port sharing (by setting portSharingEnabled =true on the transport binding element) or the service using net.tcp is deployed in IIS worker process (w3wp.exe), it implicitly allows an external process (namely the SMSvcHost.exe, which hosts the Net.Tcp Port Sharing Service) to manage the TCP socket on its behalf.

 

When configured in this way, any socket settings specified on the service's transport binding element are ignored in favor of the socket settings specified by SMSvcHost.exe.

 

Sometimes you need to change the default configuration for the Net.Tcp Port Sharing Service in SMSvcHost.exe.config because the default values (listenBacklog=”10”, maxPendingAccepts=”2”, maxPendingConnections=”10”) are conservative. With the default configuration, the WCF client may receive the communication exception with the message while the burst load arrives:

 

 The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue.

 

 If we check the network trace, we should find the connection is reset by the server side immediately after the TCP connection is established.

 

There are some discussions about changing the Port Sharing service configurations. Here I list some common mistakes the users may make while they try to modify the configurations.

 

1.       Modify the wrong SMSvcHost.exe.config file

 

Your WCF service is using .NET Framework 3.0. You may think you need to modify SMSvcHost.exe.config file under .NET Framework 3.0 folder. For example:

 

C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ SMSvcHost.exe.config

 

 

Unfortunately you may modify the wrong file. If .NET Framework 4.0 is installed, Net.Tcp Port Sharing Service is running in smsvchost.exe located under .NET Framework 4.0 folder. Therefore you need to modify:

 

C:\Windows\Microsoft.NET\Framework\v4.0.30319\SMSvcHost.exe.config

 

 

Before you modify the configuration, please manually check the Properties page of Net.Tcp Port Sharing Service in Services.msc to locate the correct SMSvcHost.exe.config file.

 

 

 

2.       Directly modify the sample settings in  SMSvcHost.exe.config file:

 

The SMSvcHost.exe.config file contains the sample settings. See below:

 

        <net.tcp listenBacklog="10" maxPendingConnections="100" maxPendingAccepts="2" receiveTimeout="00:00:10" teredoEnabled="false">

            <allowAccounts>

                // LocalSystem account

                <add securityIdentifier="S-1-5-18"/>

 

                // LocalService account

                <add securityIdentifier="S-1-5-19"/>

               

                // Administrators account

                <add securityIdentifier="S-1-5-20"/>

               

                // Network Service account

                <add securityIdentifier="S-1-5-32-544" />

               

                // IIS_IUSRS account (Vista only)

                <add securityIdentifier="S-1-5-32-568"/>

            </allowAccounts>

        </net.tcp>

 

You may use Notepad to open the file and search the string “maxPendingConnections” and then replace the existing value with the new value. Then you save the file.

 

Unfortunately your modification will *not* take effect.

 

If you go through the whole file carefully, you may notice that the above sample settings are in the comment:

 

   <!-- Below are some sample config settings:  

  <system.serviceModel.activation>

   <net.tcp

 

    </system.serviceModel.activation>

    -->

 

 

Actually it is difficult to identify this comment in a plain text editor. And the above sample is an invalid sample:  Double-slash should be an invalid XML tag:

 

            <allowAccounts>

                // LocalSystem account

                <add securityIdentifier="S-1-5-18"/>

 

                // LocalService account

                <add securityIdentifier="S-1-5-19"/>

               

                // Administrators account

                <add securityIdentifier="S-1-5-20"/>

               

                // Network Service account

                <add securityIdentifier="S-1-5-32-544" />

               

                // IIS_IUSRS account (Vista only)

                <add securityIdentifier="S-1-5-32-568"/>

 

 

If we simply remove the comment tag (<!--  -->), the configuration file will become invalid XML file.

 

While you modify the SMSvcHost.exe.config file, please do pay attention to the sample settings in the comment.

 

 

3.       Restart Net.Tcp Port Sharing Service to make the modification take effect

 

After the modification, usually you need to restart the service (Net.Tcp Port Sharing Service) to make the modification take effect.

 

Unfortunately simply restarting Net.Tcp Port Sharing Service may not work.

 

To make the modification to SMSvcHost.exe.config file take effect, we have to restart the process SMSvcHost.exe. There may be several services running in the same SMSvcHost.exe. In addition to Net.Tcp Port Sharing Service and Net.Tcp Listener Adapter, Net.Pipe Listener Adapter is also running in SMSvcHost.exe if it is started.

 

Therefore you need to manually stop all of the above services and check whether SMSvcHost.exe disappears in Task Manager. Please do make sure SMSvcHost.exe does not exist. Then start the above services again. This time the modification will take effect.

 

 

 

 Regards,

XinJin from APGC DSI Team

 

 

 

Leave a Comment
  • Please add 6 and 2 and type the answer here:
  • Post
  • Wow. Awesome write-up. I ran into these exact issues when hosting my net.tcp WCF service in IIS7. Thank you!

  • I love you dude!!!

  • Wow, I was struggling with that for a long time. Thanks.

  • don't forget Net.Msmq Listener Adapter...Great work with the post

  • one more thing, you can get all windows services in C# for a specific executable by running this code below.

    I ran the following code in LINQPad with adding the System.Management as a reference:

    void Main()

    {

      System.Management.WqlObjectQuery wqlObjectQuery = new System.Management.WqlObjectQuery(string.Format("SELECT * FROM Win32_Service WHERE PathName like '%{0}%'", serviceName));

      System.Management.ManagementObjectSearcher managementObjectSearcher = new System.Management.ManagementObjectSearcher(wqlObjectQuery);

      System.Management.ManagementObjectCollection managementObjectCollection = managementObjectSearcher.Get();

      foreach (System.Management.ManagementObject managementObject in managementObjectCollection)

      {

          Console.WriteLine(managementObject.GetPropertyValue("Name").ToString());

      }

    }

Page 1 of 1 (5 items)