WCF与tcp绑定和portSharingEnabled问题

时间:2014-01-24 13:59:19

标签: wcf tcpportsharing

我在配置文件中添加portSharingEnabled功能的那一刻然后我收到了错误名称

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.

说实话,我只是不明白为什么我会收到这个错误以及如何修复它。

这是我的配置文件详细信息

<?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>

这样我试着开始服务。

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();
            }
        }
    }

请指导我做什么以及我需要在配置文件中添加什么来修复此错误。感谢

2 个答案:

答案 0 :(得分:3)

启动Microsoft Visual Studio 20时,右键单击该图标并选择“以管理员身份运行”。

答案 1 :(得分:1)

停止以下所有服务,然后按顺序开始:

  • Net.Tcp侦听器适配器

  • Net.Tcp端口共享服务

  • Net.Pipe侦听器适配器