【问题标题】:WCF error with net.tcp "The service endpoint failed to listen on the URI because access was denied带有 net.tcp 的 WCF 错误“服务端点未能侦听 URI,因为访问被拒绝
【发布时间】:2014-07-04 14:39:08
【问题描述】:

在我属于管理员组的 Windows 8.1 计算机上托管 WCF Net.Tcp 服务时出现以下错误: 服务端点未能侦听 URI 'net.tcp://localhost:9001/dataservice',因为访问被拒绝。验证当前用户是否在 SMSvcHost.exe.config 的相应 allowAccounts 部分中被授予访问权限。

我什至按照建议将用户添加到配置中:

<?xml version="1.0" encoding="utf-8"?>
<!-- The configuration file for SMSvcHost.exe -->
<configuration>
    <runtime>
        <gcConcurrent enabled="false" />
    </runtime>
    <system.serviceModel>
        <!-- SMSvcHost ETW traces are redirected by default to an etwProviderId different from WCF's default. 
             To trace to the default provider, remove the etwProviderId attribute below. -->
        <diagnostics performanceCounters="Off" etwProviderId="{f18839f5-27ff-4e66-bd2d-639b768cf18b}"/>
    </system.serviceModel>
    <system.serviceModel.activation>
    <net.tcp listenBacklog="10" maxPendingConnections="100" maxPendingAccepts="2" receiveTimeout="00:00:10" teredoEnabled="false">
            <allowAccounts>
                <add securityIdentifier="S-1-5-18"/>

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

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

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


        <add securityIdentifier="S-1-5-21-2476327175-1934278006-4092406606"/>
            </allowAccounts>
        </net.tcp>
    <net.pipe maxPendingConnections="100" maxPendingAccepts="2" receiveTimeout="00:00:10">
            <allowAccounts>
                <add securityIdentifier="S-1-5-18"/>

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

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

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


        <add securityIdentifier="S-1-5-21-2476327175-1934278006-4092406606"/>
            </allowAccounts>
        </net.pipe>
        <diagnostics performanceCountersEnabled="true" />
    </system.serviceModel.activation>
</configuration>

但仍然出现相同的错误,这可以正常工作,无需在 W7 机器上更改配置,有什么想法吗?

【问题讨论】:

    标签: c# .net wcf nettcpbinding


    【解决方案1】:

    一步一步:

    1. Windows Sysinternals Live 下载工具PSGETSID.EXE。这是 Sysinternals 工具的 Microsoft 实时存储库。
    2. 执行命令:psgetsid.exe [您的用户名]
    3. 这将列出您的用户名的 SID。记下来。
    4. 打开 Windows 服务
    5. 右键单击Net.Tcp 端口共享服务,然后在菜单上选择属性
    6. 常规选项卡中,找到可执行文件路径。打开 Windows 资源管理器 并转到该文件夹​​。这是运行服务的文件夹。
    7. 找到并打开文件SMSvcHost.exe.config
    8. 添加以下值:

      <system.serviceModel.activation>
          <net.tcp listenBacklog="16" maxPendingAccepts="4" maxPendingConnections="100" receiveTimeout="00:00:30" 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"/>  
                  <!-- Your user account SID -->
                  <add securityIdentifier="Your SID Here" />
              </allowAccounts>  
          </net.tcp>          
          <diagnostics performanceCountersEnabled="true" />
      </system.serviceModel.activation>
      
    9. 将更改保存到文件 SMSvcHost.exe.config

    10. 重新启动 Net.Tcp 端口共享服务

    完成!

    希望对您有所帮助。

    【讨论】:

      【解决方案2】:

      按照here 的描述更新 smsvchost.exe.config 文件的“allowedAccounts”标记部分,然后重新启动 Net.Tcp 端口共享服务,但仍然遇到此错误。但是,在该流程的同一实例中运行着其他服务。共享同一个流程实例的服务有:

      Net.Tcp Listener Adapter
      Net.Tcp Port Sharing Service
      Net.Pipe Listener Adapter
      Net.Msmq Listener Adapter Correction:  Net.Msmq service actually runs in different instance of SMSvcHost.exe, so you shouldn't have to restart that service.
      

      如果您的计算机上正在运行这些服务中的任何一个,那么您必须停止所有这些服务,然后重新启动它们,以便获取对配置文件的更改。重启机器也能解决问题。

      【讨论】:

      • 我的机器上似乎没有运行这些服务,但为了确保,我确实尝试在配置更改后重新启动机器,但仍然出现相同的错误。
      【解决方案3】:

      我以为我在配置中添加了正确的 sid,但实际上我使用了错误的 sid。 为了获取 sid,我使用了 cmd psgetsid,假设这会给我当前登录的用户,即我自己,但不是,然后我使用 cmd psgetid [username],这给了我一个不同的 sid。使用了这个,现在它可以工作了。

      【讨论】:

        【解决方案4】:

        我在 Windows 10 上遇到了同样的问题,以管理员身份运行 Visual Studio 为我解决了这个问题。

        【讨论】:

          【解决方案5】:

          我已经重新启动了它工作的服务。开始-->服务-->Net.Tcp端口共享服务。右键单击并重新启动此服务。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2013-10-11
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-11-15
            • 2012-02-21
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多