我有一个托管在Windows服务中的WCF服务。Windows服务有一个像这样的OnStart
方法:
protected override void OnStart(string[] args)
{
serviceHost = new ServiceHost(typeof (RouterService));
serviceHost.Open();
}
目前我的代码非常简单,因为我正在试图找到问题。由于我没有放置任何错误处理,所以此时的任何异常情况都会阻止服务正确地启动。服务会启动,然后立即停止。
我的WCF服务配置文件如下:
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<system.serviceModel>
<services>
<service name="WcfService.RouterService"
behaviorConfiguration="serviceBehavior" >
<endpoint address="RouterService" contract="WcfService.IRouterService" binding="wsHttpBinding" bindingConfiguration="NoSecurity" />
<endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="NoSecurity">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
另外,我已经添加了NETWORK SERVICE用户(服务正在运行的用户)以便能够在指定的端口上监听Http:
netsh http add urlacl url=http://+:8000/ user="NETWORK SERVICE"
现在,在客户端中,我选择添加服务引用
。我可以找到服务器,VS也能创建配置并生成代理文件。然后在客户端内部,我创建了代理的实例,并打开了它。一切仍然很好。但是在调用代理的第一个方法时,我得到了以下异常:
The HTTP service located at http://localhost:8000/RouterService is too busy.
我知道我的客户端是唯一尝试连接此服务的东西,那么为什么会出现这个错误消息呢?如何修复它?当它尝试调用该方法时不会超时,它几乎立即抛出异常。
编辑
好的,现在我发现我的TestServer(不是Windows客户端,而是控制台应用程序)也显示相同的错误。早些时候它没有,WCF服务或TestServer也没有更改过。
然后我尝试将端口从8000改为8080,然后它就起作用了。然后我对Windows服务进行了相同的操作,也起作用了(在新端口上运行netsh http
命令之后)
所以某些原因导致端口8000上的http出了问题。当然,我也尝试重新启动系统。
这让我感到困惑,如果有人知道这里发生了什么事情,我会很感激。