Hi,
I have a problem related to creating an instance of a WCF ServiceHost withing a set of unit tests and a project that is build within an integration build in TFSBuild. The code used in the unit test is:
[TestMethod]
public void Service_Can_Be_Dynamically_Hosted()
{
ServiceHost host = new ServiceHost(typeof(DiscoveryService));
host.Open();
host.Close();
}
The configuration for the service, although it can be created through code directly, is located in an .config file containing the following details:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="TappingBoard.Core.Network.DiscoveryServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="TappingBoard.Core.Network.DiscoveryServiceBehavior"
name="TappingBoard.Core.Network.Services.DiscoveryService">
<endpoint address="" binding="wsHttpBinding" contract="TappingBoard.Core.Network.Services.IDiscoveryService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8001/TappingBoard/DiscoveryService/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
The unit test is working perfectly in the client machines with both administrator users and non-admin users executing the tests locally. In the case of the TFS Build Server, the user that is launching the Build is called TFSBuild and is member of Domain Users and a local Administrator in the TFS Build Server.
Executing the same unit test in the Build Server launches the following exception:
System.ServiceModel.AddressAccessDeniedException: HTTP could not register URL http://+:8001/TappingBoard/DiscoveryService/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details). ---> System.Net.HttpListenerException: Access is denied
As the TFS Build Server is using port 80 to expose some reports and webs over IIS, I changed the port to be used by the WCF Service to 8001. It didn't worked before with port 80 either.
Is there any option to have this test run on the TFS Build Server? Should I configure anything extra on my build?
In terms of providing the most useful information, the systems used are:
- Dev Machines: VS2010TS, Windows 7RTM
- Server Machines: TFS2010, Windows Server 2008 R2 RTM
Thanks in advance for your time and support.
Bests, Miguel.