我有一个与在TFSBuild的集成构建中创建WCF ServiceHost实例相关的问题。在单元测试中使用的代码如下:
[TestMethod]
public void Service_Can_Be_Dynamically_Hosted()
{
ServiceHost host = new ServiceHost(typeof(DiscoveryService));
host.Open();
host.Close();
}
服务的配置,虽然可以通过代码直接创建,但是实际上是在一个包含以下详细信息的.config文件中:
<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>
在客户端机器上,单元测试在管理员用户和非管理员用户本地执行时都能正常工作。在TFS Build Server的情况下,启动构建的用户称为TFSBuild,是Domain Users的成员,并且是TFS Build Server中的本地管理员。
在Build Server上执行相同的单元测试会引发以下异常:
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
作为TFS构建服务器使用端口80来公开一些报告和Web,因此我将WCF服务要使用的端口更改为8001。即使以前使用端口80也没有起作用。
有没有在TFS构建服务器上运行此测试的选项?我是否需要在我的构建中配置任何额外的内容?
就提供最有用信息而言,所使用的系统如下:
- Dev Machines: VS2010TS, Windows 7RTM - Server Machines: TFS2010, Windows Server 2008 R2 RTM
感谢您的时间和支持。
最好的问候, 米格尔。