WCF with tcp binding and portSharingEnabled issue

1.5k Views Asked by At

the moment i add portSharingEnabled feature in my config file then i am getting error called

The service endpoint failed to listen on the URI 'net.tcp://localhost:5555/Calculator'
because access was denied.  Verify that the current user is granted access in the 
appropriate allowAccounts section of SMSvcHost.exe.config.

to be very honest i just do not understand why i am getting this error and how to fix it.

here is my config file details

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <services>
            <service name="CalculatorServer.Calculator" behaviorConfiguration="CalculatorBehavior">
                <endpoint address="net.tcp://localhost:5555/Calculator" binding="netTcpBinding" bindingConfiguration="PortSharingBinding"
                    contract="CalculatorInterFace.ICalculator" />

                <endpoint address="net.tcp://localhost:5555/Calculator/mex"
                          binding="mexTcpBinding" contract="IMetadataExchange"/>
            </service>
        </services>
        <bindings>
            <netTcpBinding>
                <binding name="PortSharingBinding" portSharingEnabled="true">
                    <security mode="None"/>
                </binding>
            </netTcpBinding>
        </bindings>
        <behaviors>
            <serviceBehaviors>
                <behavior name="CalculatorBehavior">
                    <serviceMetadata httpGetEnabled="false"/>
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
</configuration>

and this way i am try to start my service.

public class Program
    {
        static void Main(string[] args)
        {
            using (ServiceHost host = new ServiceHost(typeof(Calculator)))
            {
                host.Open();
                Console.WriteLine("Server Started");
                Console.ReadLine();
                host.Close();
            }
        }
    }

please guide me what to do and what else i need to add in my config file to fix this error. thanks

2

There are 2 best solutions below

0
On

Stop all of the below services, then start in order:

  • Net.Tcp Listener Adapter

  • Net.Tcp Port Sharing Service

  • Net.Pipe Listener Adapter

0
On

when you start Microsoft Visual Studio 20??, right-click the icon and select "Run as administrator".