この問題についてすでにかなりの質問があることは知っていますが、私の問題を解決する返信はありません。
サーバー上で NetTcpBinding を実行していますが、ときどき (20 から 60 の呼び出しのうちの 1 つなど、完全にランダムであるとは限りません)、クライアント側で次の例外を受け取ります。
ソケット接続が中止されました。これは、メッセージの処理中にエラーが発生したか、リモート ホストが受信タイムアウトを超過したか、基になるネットワーク リソースの問題が原因である可能性があります。ローカル ソケットのタイムアウトは「00:01:00」でした。
クライアントの接続が遅い場合、この例外がより頻繁に発生することに気付きました。
また、記載されているタイムアウトは 1 分ですが、例外は 1 秒ほど後に既に発生しています。
私がやること:
var client = GetClient();
client.Open();
bool success = client.Call(); // Exception occurs here (the return value is a bool)
サーバー側でこの例外が発生することもあります。
データの送信中に TCP エラー (995: スレッドの終了またはアプリケーションの要求により、I/O 操作が中止されました) が発生しました。
サーバー トレースを有効にしていますが、同じ例外が発生し、それ以上の洞察は得られません。
私のGetClient:
NetTcpBinding netTcpBinding = new NetTcpBinding
{
CloseTimeout = new TimeSpan(0, 0, 30),
OpenTimeout = new TimeSpan(0, 0, 30),
TransferMode = TransferMode.Buffered,
ListenBacklog = 2,
MaxConnections = 2,
MaxReceivedMessageSize = 10485600,
ReaderQuotas = { MaxStringContentLength = 1048576 },
ReliableSession = { Enabled = false },
Security =
{
Mode = SecurityMode.Transport,
Transport = { ClientCredentialType = TcpClientCredentialType.None, ProtectionLevel = ProtectionLevel.EncryptAndSign },
Message = { ClientCredentialType = MessageCredentialType.Windows }
}
};
サービスからの重要な構成:
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true" httpsHelpPageEnabled="true" />
<serviceAuthorization principalPermissionMode="Custom" serviceAuthorizationManagerType="My.Service.WCF.Tools.CustomAuthorizationManager, My.Service.WCF">
<authorizationPolicies>
<clear/>
<add policyType="My.Service.WCF.Tools.CustomAuthorizationPolicy, My.Service.WCF" />
</authorizationPolicies>
</serviceAuthorization>
<serviceCredentials>
<serviceCertificate findValue="MyService" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
</serviceCredentials>
<serviceThrottling maxConcurrentCalls="65536" maxConcurrentSessions="65536" maxConcurrentInstances="65536" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="ServiceBinding" receiveTimeout="00:05:00" maxConnections="65536" listenBacklog="65536">
<transactionFlow />
<sslStreamSecurity requireClientCertificate="false" />
<binaryMessageEncoding />
<tcpTransport transferMode="Buffered" portSharingEnabled="true" maxReceivedMessageSize="1048576" maxPendingConnections="65536" maxPendingAccepts="10">
<connectionPoolSettings leaseTimeout="00:05:00" idleTimeout="00:05:00" maxOutboundConnectionsPerEndpoint="65536" />
</tcpTransport>
</binding>
<binding name="MexBinding" receiveTimeout="00:05:00" maxConnections="65536" listenBacklog="65536">
<tcpTransport transferMode="Buffered" portSharingEnabled="true" maxReceivedMessageSize="1048576" maxPendingConnections="65536" maxPendingAccepts="10">
<connectionPoolSettings leaseTimeout="00:05:00" idleTimeout="00:05:00" maxOutboundConnectionsPerEndpoint="65536" />
</tcpTransport>
</binding>
</customBinding>
</bindings>
既にサービス リファレンスを更新し、バッファとサイズの一部を変更しようとしましたが、うまくいきませんでした (bool のみが返されるため、そこで問題が発生することはないと思います)。
以下を使用して修正:
OperationContext.Current.OperationCompleted += Test;
private void Test(object sender, EventArgs e)
{
OperationContext.Current.Channel.Close();
}
Abort ではなく Close メソッドを使用してください。