[英]WCF EndpointNotFoundException when running as NetworkService
[英]WCF: EndpointNotFoundException after running for a couple of seconds
我正在使用兩個應用程序,一個具有配置為使用net.tcp綁定的自托管服務。 該服務的ServiceBehaviorAttribute配置為:
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple,
InstanceContextMode = InstanceContextMode.Single,
IncludeExceptionDetailInFaults = true,
UseSynchronizationContext = false,
ValidateMustUnderstand = false)]
對於服務和客戶端,transferMode設置為Streamed,超時為:
closeTimeout="00:01:00"
openTimeout="00:00:30"
receiveTimeout="00:02:30"
sendTimeout="00:02:30"
MaxConnections設置為500,ServiceThrottlingBehavior使用WCF 4默認值:
我使用的是四核機器,並啟用了Net.Tcp端口共享服務。
客戶端應用程序具有使用ChannelFactory類創建的服務的單個通道。 創建通道后,會生成100個線程。 每個線程使用該通道以每秒一條消息的頻率向服務器發送消息。
運行ok幾秒鍾后(客戶端向服務器發送消息並正確接收它們)會拋出EndpointNotFoundException,並顯示以下消息:
Could not connect to net.tcp://localhost/service. The connection attempt lasted
for a time span of 00:00:02.1777100. TCP error code 10061: No connection could
be made because the target machine actively refused it 127.0.0.1:808.
奇怪的事情是:
我做了很多測試,減少線程數量,增加線程數量,更改關閉,打開,接收和發送超時值到更低和更高的值,為maxConnections設置更高的值,但結果總是相同的,在某些時候拋出EndpointNotFoundException。 我即將放棄並更改代碼,以便每個線程都有自己的通道,希望這可以解決問題,但我想知道為什么會發生這種情況。 如果有人知道我做錯了什么或者能指出我正確的方向繼續調查它會有所幫助。
默認情況下,Windows不啟用端口共享。 我會檢查你是否正確啟用它( 見這里 )。
如果可能,您還可以嘗試更改一個應用程序的端口,或者在VM中測試一個應用程序。
此外,對於可能具有相同問題的任何其他人,請執行Diego已完成並檢查配置中是否啟用了端口共享。 將portSharingEnabled="true"
添加到綁定:
<system.serviceModel>
<bindings>
<netTcpBinding name="portSharingBinding"
portSharingEnabled="true" />
<services>
<service name="MyService">
<endpoint address="net.tcp://localhost/MyService"
binding="netTcpBinding"
contract="IMyService"
bindingConfiguration="portSharingBinding" />
</service>
</services>
</system.serviceModel>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.