パフォーマンス上の理由から、自己ホスト型の.Net4.0WCFサービスをWsHttpBindingからNetTcpBindingに変換しようとしています。このサービスは、WsHttpBindingで問題なく機能します。
不思議なことに、NetTcpBindingに切り替えた後、サービスは機能しているようです。(サービスはメッセージをエンタープライズメッセージングシステムに送信し、メッセージは送信され、クライアントはエラーを受信しません)ただし、次のエラーがサーバーログに書き込まれます。
Error: Service: MessageSenderService, Details: System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused
by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue.
Local socket timeout was '10675199.02:48:05.4775807'. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.ServiceModel.Channels.SocketConnection.HandleReceiveAsyncCompleted()
at System.ServiceModel.Channels.SocketConnection.BeginReadCore(Int32 offset,Int32 size, TimeSpan timeout, WaitCallback callback, Object state)
--- End of inner exception stack trace ---
at System.ServiceModel.Channels.SocketConnection.BeginReadCore(Int32 offset,Int32 size, TimeSpan timeout, WaitCallback callback, Object state)
at System.ServiceModel.Channels.TracingConnection.BeginRead(Int32 offset, Int32 size, TimeSpan timeout, WaitCallback callback, Object state)
at System.ServiceModel.Channels.SessionConnectionReader.BeginReceive(TimeSpan timeout, WaitCallback callback, Object state)
at System.ServiceModel.Channels.SynchronizedMessageSource.ReceiveAsyncResult.PerformOperation(TimeSpan timeout)
at System.ServiceModel.Channels.SynchronizedMessageSource.SynchronizedAsyncResult`1..ctor(SynchronizedMessageSource syncSource, TimeSpan timeout, AsyncCallback callback, Object state)
at System.ServiceModel.Channels.TransportDuplexSessionChannel.BeginReceive(TimeSpan timeout, AsyncCallback callback, Object state)
at System.ServiceModel.Channels.TransportDuplexSessionChannel.TryReceiveAsyncResult..ctor(TransportDuplexSessionChannel channel, TimeSpan timeout, AsyncCallback callback, Object state)
at System.ServiceModel.Channels.TransportDuplexSessionChannel.BeginTryReceive(TimeSpan timeout, AsyncCallback callback, Object state)
at System.ServiceModel.Dispatcher.ErrorHandlingReceiver.BeginTryReceive(TimeSpan timeout, AsyncCallback callback, Object state)
この場合も、WsHttpBindingを使用すると、サーバーログでエラーは発生しません。
サーバー構成:
<service behaviorConfiguration="debugEnabled" name="My.Service">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="netTcpBindingConfig"
contract="My.Service.Contract" />
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
....
<behaviors>
<serviceBehaviors>
<behavior name="debugEnabled">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentSessions="200" maxConcurrentCalls="500" maxConcurrentInstances="200"/>
<serviceMetadata httpGetEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
....
<bindings>
<netTcpBinding>
<binding name="netTcpBindingConfig" maxReceivedMessageSize="5242880" closeTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00" openTimeout="00:01:00">
<readerQuotas maxArrayLength="5242880" />
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
構成ではなく、コードでクライアントバインディングを構築します。これは次のようになります。
return new NetTcpBinding(SecurityMode.None, reliableSessionEnabled)
{
MaxBufferPoolSize = Int32.MaxValue,
MaxReceivedMessageSize = Int32.MaxValue,
ReaderQuotas = new XmlDictionaryReaderQuotas
{
MaxArrayLength = Int32.MaxValue,
MaxDepth = Int32.MaxValue,
MaxStringContentLength = Int32.MaxValue
},
ReceiveTimeout = TimeSpan.FromMinutes(1.0),
CloseTimeout = TimeSpan.FromMinutes(1.0),
OpenTimeout = TimeSpan.FromMinutes(1.0),
SendTimeout = TimeSpan.FromMinutes(1.0)
};
そこに何かアイデアはありますか?
編集:負荷がかかっているときだけでなく、サービスへのすべての呼び出しでエラーが表示されることを追加したいと思います。要求メッセージと応答メッセージは非常に小さいため、メッセージサイズとは関係がない可能性があります。エラーはほぼ瞬時に書き込まれるため、タイムアウトの問題ではありません。