Verify that the current user is granted access in the appropriate allowAccounts section of SMSvcHost.exe.config
07 Mar 2011 | windows | comments | editQuick tip that maybe will save others time:
In Windows 7 ( and maybe Vista) when hosting a WCF Service in a console application AS A USER and not as administrator, you might get an exception telling you that you don't have access to register with the net.tcp port sharing service.
To resolve this problem:
Download PsGetSid ( this will give you the Security Identifier - SID for your user or user group )
Find and open SMSvcHost.exe.config ( usualy in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\SMSvcHost.exe.config or c:\Windows\Microsoft.NET\Framework\v4.0.30319\SMSvcHost.exe.config )
Run psgetsid.exe
to get the SID ( should look something like this S-1-5-21-1754548885-2506776180-2303324228-4659 ) By default the SMSvcHost.exe.config contains a section
which has a child which has a child. The IMPORTANT part if you are using an editor that does not do syntax highlight for XML - THE ABOVE SECTION IS COMMENTED by DEFAULT so adding child has not effect. YOU NEED TO ADD A NEW
SECTION with it's children sections to make it work ( or uncomment the existing one and removing the // comments which are not valid xml ). Restart the net.tcp portsharing service and you are good to go.
In the end you should have something like this:
1 < ?xml version="1.0" encoding="utf-8"?>
2 <!-- The configuration file for SMSvcHost.exe -->
3 <configuration>
4 <runtime>
5 <gcconcurrent enabled="false" />
6 </runtime>
7 <system.serviceModel>
8 <diagnostics performanceCounters="Off" etwProviderId="{f18839f5-27ff-4e66-bd2d-639b768cf18b}"/>
9 </system.serviceModel>
10 <system.serviceModel.activation>
11 <net.tcp listenBacklog="10" maxPendingConnections="100" maxPendingAccepts="2" receiveTimeout="00:00:10" teredoEnabled="false">
12 <allowaccounts>
13 <add securityIdentifier="S-1-5-21-1754548885-2506776180-2303324228-4659"/>
14 </allowaccounts>
15 </net.tcp>
16 </system.serviceModel.activation>
17 </configuration>
Also you might need to grant access to the user to register as a listener for an url:
netsh http add urlacl url=http://+: <port>/MyUri user=DOMAIN\user
I have to admin the most of the time i've spent on this issue was because i was modifying the commented section in the the config xml.