WCF非同期呼び出し-eventhandlerでの例外
eventhandlerを使用してWCFメソッドを非同期で呼び出しています。'EventAddCallback'イベントでエラーが発生し、'e.Error'は次のエラーを示します。誰もが理由を知っていますか?サンプルコード、エラー情報、トレース情報、および試したオプションを追加しました。
System.Reflection.TargetInvocationException:操作中に例外が発生し、結果が無効になりました。例外の詳細については、InnerExceptionを確認してください。---> System.ServiceModel.CommunicationException:https://demosite.com/ourservice.asmxへのHTTP応答の受信中にエラーが発生しました。これは、HTTPプロトコルを使用していないサービスエンドポイントバインディングが原因である可能性があります。これは、サーバーによってHTTP要求コンテキストが中止されたことが原因である可能性もあります(おそらくサービスのシャットダウンが原因です)。詳細については、サーバーログを参照してください。---> System.Net.WebException:基になる接続が閉じられました:受信時に予期しないエラーが発生しました。---> System.IO.IOException:トランスポート接続からデータを読み取れません:既存の接続がリモートホストによって強制的に閉じられました。---> System.Net.Sockets.SocketException:既存の接続がリモートホストによって強制的に閉じられました
トレースを有効にすると、表示されます。
System.ServiceModel.CommunicationException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
An error occurred while receiving the HTTP response to https://demosite.com/ourservice.asmx. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
-->System.Net.WebException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-->The underlying connection was closed: An unexpected error occurred on a receive.
------>System.IO.IOException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
------>Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
---------->System.Net.Sockets.SocketException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
---------->An existing connection was forcibly closed by the remote host
Options I tried..
1. Increased
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
2. Enabled 'Keep Alive', increased buffer size(s)
<httpsTransport maxReceivedMessageSize="2147483647" keepAliveEnabled="true" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" />
3. added endpointBehaviors
<endpointBehaviors>
<behavior name="demo">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
class Program
{
static ManualResetEvent closeapp = new ManualResetEvent(false);
static void Main(string[] args)
{
wcfclient.AddCompleted += new EventHandler<AddCompletedEventArgs>(EventAddCallback);
wcfclient.AddAsync(employees);
closeapp.WaitOne();
}
static void EventAddCallback(object sender, AddCompletedEventArgs e)
{
try
{
if (e.Error != null)
{
wcfclient.Close();
closeapp.Set();
}else
{
//Continue with other calls.
}
}
catch (Exception ex) {
throw ex;
}
}
}