Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Dispatcher / ErrorHandlingReceiver.cs / 1 / ErrorHandlingReceiver.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel.Dispatcher
{
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
class ErrorHandlingReceiver
{
ChannelDispatcher dispatcher;
IChannelBinder binder;
internal ErrorHandlingReceiver(IChannelBinder binder, ChannelDispatcher dispatcher)
{
this.binder = binder;
this.dispatcher = dispatcher;
}
internal void Close()
{
try
{
this.binder.Channel.Close();
}
catch (Exception e)
{
if (DiagnosticUtility.IsFatal(e))
{
throw;
}
this.HandleError(e);
}
}
void HandleError(Exception e)
{
if (this.dispatcher != null)
{
this.dispatcher.HandleError(e);
}
}
void HandleErrorOrAbort(Exception e)
{
if ((this.dispatcher == null) || !this.dispatcher.HandleError(e))
{
if (this.binder.HasSession)
{
this.binder.Abort();
}
}
}
internal bool TryReceive(TimeSpan timeout, out RequestContext requestContext)
{
try
{
return this.binder.TryReceive(timeout, out requestContext);
}
catch (CommunicationObjectAbortedException)
{
requestContext = null;
return true;
}
catch (CommunicationObjectFaultedException)
{
requestContext = null;
return true;
}
catch (CommunicationException e)
{
this.HandleError(e);
requestContext = null;
return false;
}
catch (TimeoutException e)
{
this.HandleError(e);
requestContext = null;
return false;
}
catch (Exception e)
{
if (DiagnosticUtility.IsFatal(e))
{
throw;
}
this.HandleErrorOrAbort(e);
requestContext = null;
return false;
}
}
internal IAsyncResult BeginTryReceive(TimeSpan timeout, AsyncCallback callback, object state)
{
try
{
return this.binder.BeginTryReceive(timeout, callback, state);
}
catch (CommunicationObjectAbortedException)
{
return new ErrorHandlingCompletedAsyncResult(true, callback, state);
}
catch (CommunicationObjectFaultedException)
{
return new ErrorHandlingCompletedAsyncResult(true, callback, state);
}
catch (CommunicationException e)
{
this.HandleError(e);
return new ErrorHandlingCompletedAsyncResult(false, callback, state);
}
catch (TimeoutException e)
{
this.HandleError(e);
return new ErrorHandlingCompletedAsyncResult(false, callback, state);
}
catch (Exception e)
{
if (DiagnosticUtility.IsFatal(e))
{
throw;
}
this.HandleErrorOrAbort(e);
return new ErrorHandlingCompletedAsyncResult(false, callback, state);
}
}
internal bool EndTryReceive(IAsyncResult result, out RequestContext requestContext)
{
ErrorHandlingCompletedAsyncResult handlerResult = result as ErrorHandlingCompletedAsyncResult;
if (handlerResult != null)
{
requestContext = null;
return ErrorHandlingCompletedAsyncResult.End(handlerResult);
}
else
{
try
{
return this.binder.EndTryReceive(result, out requestContext);
}
catch (CommunicationObjectAbortedException)
{
requestContext = null;
return true;
}
catch (CommunicationObjectFaultedException)
{
requestContext = null;
return true;
}
catch (CommunicationException e)
{
this.HandleError(e);
requestContext = null;
return false;
}
catch (TimeoutException e)
{
this.HandleError(e);
requestContext = null;
return false;
}
catch (Exception e)
{
if (DiagnosticUtility.IsFatal(e))
{
throw;
}
this.HandleErrorOrAbort(e);
requestContext = null;
return false;
}
}
}
internal void WaitForMessage()
{
try
{
this.binder.WaitForMessage(TimeSpan.MaxValue);
}
catch (CommunicationObjectAbortedException) { }
catch (CommunicationObjectFaultedException) { }
catch (CommunicationException e)
{
this.HandleError(e);
}
catch (Exception e)
{
if (DiagnosticUtility.IsFatal(e))
{
throw;
}
this.HandleErrorOrAbort(e);
}
}
internal IAsyncResult BeginWaitForMessage(AsyncCallback callback, object state)
{
try
{
return this.binder.BeginWaitForMessage(TimeSpan.MaxValue, callback, state);
}
catch (CommunicationObjectAbortedException)
{
return new WaitCompletedAsyncResult(callback, state);
}
catch (CommunicationObjectFaultedException)
{
return new WaitCompletedAsyncResult(callback, state);
}
catch (CommunicationException e)
{
this.HandleError(e);
return new WaitCompletedAsyncResult(callback, state);
}
catch (Exception e)
{
if (DiagnosticUtility.IsFatal(e))
{
throw;
}
this.HandleErrorOrAbort(e);
return new WaitCompletedAsyncResult(callback, state);
}
}
internal void EndWaitForMessage(IAsyncResult result)
{
WaitCompletedAsyncResult handlerResult = result as WaitCompletedAsyncResult;
if (handlerResult != null)
{
WaitCompletedAsyncResult.End(handlerResult);
}
else
{
try
{
this.binder.EndWaitForMessage(result);
}
catch (CommunicationObjectAbortedException) { }
catch (CommunicationObjectFaultedException) { }
catch (CommunicationException e)
{
this.HandleError(e);
}
catch (Exception e)
{
if (DiagnosticUtility.IsFatal(e))
{
throw;
}
this.HandleErrorOrAbort(e);
}
}
}
class ErrorHandlingCompletedAsyncResult : TypedCompletedAsyncResult
{
internal ErrorHandlingCompletedAsyncResult(bool data, AsyncCallback callback, object state)
: base(data, callback, state)
{
}
}
class WaitCompletedAsyncResult : CompletedAsyncResult
{
internal WaitCompletedAsyncResult(AsyncCallback callback, object state)
: base(callback, state)
{
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AttributeSetAction.cs
- ElementsClipboardData.cs
- OleDbFactory.cs
- RelationshipEnd.cs
- SqlException.cs
- TaiwanCalendar.cs
- DynamicValueConverter.cs
- XsltQilFactory.cs
- UdpDiscoveryEndpointElement.cs
- ProviderConnectionPoint.cs
- ConstrainedDataObject.cs
- GeneralTransform3DTo2DTo3D.cs
- ChildTable.cs
- WindowsListViewScroll.cs
- ImplicitInputBrush.cs
- ProfileGroupSettings.cs
- control.ime.cs
- _BaseOverlappedAsyncResult.cs
- AutoResetEvent.cs
- HebrewCalendar.cs
- UnicodeEncoding.cs
- QuadraticBezierSegment.cs
- StrongNameUtility.cs
- HttpCapabilitiesBase.cs
- UnsafeNativeMethods.cs
- XmlWellformedWriter.cs
- XmlDocumentType.cs
- CredentialCache.cs
- UseManagedPresentationElement.cs
- RuleSetBrowserDialog.cs
- ExitEventArgs.cs
- SoapAttributeAttribute.cs
- DelimitedListTraceListener.cs
- OracleFactory.cs
- ObjectPersistData.cs
- BindingMemberInfo.cs
- RewritingSimplifier.cs
- SqlDataReaderSmi.cs
- newinstructionaction.cs
- HttpCacheVary.cs
- figurelengthconverter.cs
- Stroke.cs
- RowsCopiedEventArgs.cs
- translator.cs
- Decimal.cs
- DataControlButton.cs
- WebPartMinimizeVerb.cs
- WebAdminConfigurationHelper.cs
- AmbientValueAttribute.cs
- SqlGenericUtil.cs
- ProjectionPruner.cs
- DbConnectionPoolIdentity.cs
- StdValidatorsAndConverters.cs
- PopupRoot.cs
- LiteralControl.cs
- NumericUpDownAcceleration.cs
- OdbcRowUpdatingEvent.cs
- FontDialog.cs
- QilVisitor.cs
- CacheSection.cs
- ContractAdapter.cs
- DispatcherExceptionFilterEventArgs.cs
- DiscoveryDocumentSerializer.cs
- BufferCache.cs
- StringDictionary.cs
- SizeAnimation.cs
- Version.cs
- ReadOnlyHierarchicalDataSourceView.cs
- SymmetricAlgorithm.cs
- LambdaReference.cs
- IntPtr.cs
- AuthenticationConfig.cs
- Filter.cs
- EncoderParameters.cs
- MessageBox.cs
- AttributeCollection.cs
- PolyQuadraticBezierSegmentFigureLogic.cs
- XmlUtilWriter.cs
- XPathBuilder.cs
- ParameterElement.cs
- PriorityBindingExpression.cs
- InputLanguageManager.cs
- CustomLineCap.cs
- BitConverter.cs
- UserPreferenceChangedEventArgs.cs
- QueryInterceptorAttribute.cs
- AdornerPresentationContext.cs
- Library.cs
- control.ime.cs
- BackgroundFormatInfo.cs
- ObjectViewQueryResultData.cs
- PathSegment.cs
- Debug.cs
- TiffBitmapEncoder.cs
- SetterBaseCollection.cs
- TableLayoutStyle.cs
- TreeViewCancelEvent.cs
- EntityDataSourceValidationException.cs
- ToolStripDropDown.cs
- PluralizationService.cs