net.tcp的WCF错误"服务端点无法侦听URI,因为访问被拒绝

时间:2014-07-04 14:39:09

标签: c# .net wcf nettcpbinding

在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机器上进行配置更改,任何想法?

4 个答案:

答案 0 :(得分:1)

按照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.

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

答案 1 :(得分: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端口共享服务
  11. 完成!

    希望它有所帮助。

答案 2 :(得分:0)

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

答案 3 :(得分:0)

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