private static void OnAsyncReplyComplete(IAsyncResult result) { if (result.CompletedSynchronously) { return; } try { var state = (ContinuationState)result.AsyncState; ChannelHandler.AsyncReplyComplete(result, state); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } } }
private void ProvideFaultAndReplyFailure(RequestContext request, Exception exception, ref ErrorHandlerFaultInfo faultInfo, out bool replied, out bool replySentAsync) { replied = false; replySentAsync = false; bool requestMessageIsFault = false; try { requestMessageIsFault = request.RequestMessage.IsFault; } #pragma warning suppress 56500 // covered by FxCOP catch (Exception e) { if (Fx.IsFatal(e)) { throw; } // do not propagate non-fatal exceptions } bool enableFaults = false; if (_listener != null) { enableFaults = _listener.ChannelDispatcher.EnableFaults; } else if (_channel != null && _channel.IsClient) { enableFaults = _channel.ClientRuntime.EnableFaults; } if ((!requestMessageIsFault) && enableFaults) { this.ProvideFault(exception, ref faultInfo); if (faultInfo.Fault != null) { Message reply = faultInfo.Fault; try { try { if (this.PrepareReply(request, reply)) { if (_sendAsynchronously) { var state = new ContinuationState { ChannelHandler = this, Channel = _channel, Exception = exception, FaultInfo = faultInfo, Request = request, Reply = reply }; var result = request.BeginReply(reply, ChannelHandler.s_onAsyncReplyComplete, state); if (result.CompletedSynchronously) { ChannelHandler.AsyncReplyComplete(result, state); replied = true; } else { replySentAsync = true; } } else { request.Reply(reply); replied = true; } } } finally { if (!replySentAsync) { reply.Close(); } } } #pragma warning suppress 56500 // covered by FxCOP catch (Exception e) { if (Fx.IsFatal(e)) { throw; } this.HandleError(e); } } } }