问题
I'm getting the following error when hosting WCF Net.Tcp service on windows 8.1 machine where I'm in the administrators group: The service endpoint failed to listen on the URI 'net.tcp://localhost:9001/dataservice' because access was denied. Verify that the current user is granted access in the appropriate allowAccounts section of SMSvcHost.exe.config.
I even added the user to the config as suggested:
<?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>
But still get the same error, this works fine without any need for config change on a W7 machine, any ideas?
回答1:
Step by step:
- Download the tool PSGETSID.EXE from Windows Sysinternals Live. This is a Microsoft live repository for Sysinternals tools.
- Execute the command: psgetsid.exe [your username]
- This will list the SID for your username. Jot it down.
- Open the Windows Services.
- Right-click the Net.Tcp Port Sharing Service and select Properties on the menu.
- In the General Tab, find the Path to Executable. Open the Windows Explorer and go to that folder. This is the folder where the service is running.
- Find and open the file SMSvcHost.exe.config.
Add the following values:
<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>
Save the changes to the file SMSvcHost.exe.config.
- Restart the Net.Tcp Port Sharing Service.
Done!
Hope it helps.
回答2:
update the "allowedAccounts" tag section of the smsvchost.exe.config file as described here and then restart the Net.Tcp port sharing service but still hit this error. However there are additional services running inside of that same instance of the process. The services that share the same process instance are:
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.
If any of those services are running on your machine, then you have to stop all of them, then restart them in order for the changes to the configuration file be picked up. Restarting the machine will also do the trick.
回答3:
I thought I had added the correct sid in the config but in fact I used the wrong sid. To get hold of the sid I used the cmd psgetsid assuming this would give me the current logged in user which is myself but no, I then used cmd psgetid [username] and this gave me a different sid. Used this and now it works.
回答4:
I had the same issue on Windows 10, running visual studio as administrator fixed the issue for me.
来源:https://stackoverflow.com/questions/24576646/wcf-error-with-net-tcp-the-service-endpoint-failed-to-listen-on-the-uri-because