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
- SecurityPolicySection.cs
- DomNameTable.cs
- WindowsTokenRoleProvider.cs
- DbDataRecord.cs
- UIElementCollection.cs
- TemplateBaseAction.cs
- DesignerForm.cs
- _OSSOCK.cs
- SatelliteContractVersionAttribute.cs
- Rijndael.cs
- PolyBezierSegment.cs
- MembershipUser.cs
- ObjectView.cs
- ConfigXmlAttribute.cs
- RowsCopiedEventArgs.cs
- ActivityContext.cs
- TextTreeInsertUndoUnit.cs
- InternalControlCollection.cs
- XmlAttributeAttribute.cs
- ResXBuildProvider.cs
- ZipIOLocalFileHeader.cs
- XmlNodeList.cs
- ParenthesizePropertyNameAttribute.cs
- DBPropSet.cs
- CursorEditor.cs
- EventLogPermissionAttribute.cs
- HttpWebRequestElement.cs
- relpropertyhelper.cs
- CachedFontFamily.cs
- PersonalizationStateInfoCollection.cs
- InvalidEnumArgumentException.cs
- Setter.cs
- _UncName.cs
- FunctionUpdateCommand.cs
- WindowsComboBox.cs
- ImageCodecInfo.cs
- OverflowException.cs
- FileDetails.cs
- ClientSettingsStore.cs
- DecimalKeyFrameCollection.cs
- FormViewRow.cs
- GZipStream.cs
- ValidatingPropertiesEventArgs.cs
- DataContext.cs
- Table.cs
- Point3DAnimationUsingKeyFrames.cs
- _PooledStream.cs
- WaveHeader.cs
- SecurityProtocol.cs
- TagNameToTypeMapper.cs
- ValuePattern.cs
- TransactionManager.cs
- PreviewControlDesigner.cs
- _SpnDictionary.cs
- TraceFilter.cs
- PreviewKeyDownEventArgs.cs
- NavigatorInput.cs
- WebPartMinimizeVerb.cs
- ImageMetadata.cs
- Rfc2898DeriveBytes.cs
- ReadOnlyDictionary.cs
- UserCancellationException.cs
- CodeIterationStatement.cs
- IncrementalHitTester.cs
- DataBoundControl.cs
- ContainerVisual.cs
- StylusShape.cs
- ClientUtils.cs
- Internal.cs
- UnhandledExceptionEventArgs.cs
- AuthenticationService.cs
- WindowsIdentity.cs
- Variable.cs
- TextBounds.cs
- Decorator.cs
- LogManagementAsyncResult.cs
- MaterializeFromAtom.cs
- ConstructorBuilder.cs
- SqlClientPermission.cs
- DataGridViewButtonCell.cs
- OdbcRowUpdatingEvent.cs
- GeometryCollection.cs
- IxmlLineInfo.cs
- FixedBufferAttribute.cs
- ClockGroup.cs
- PerformanceCounterPermissionEntry.cs
- XslAst.cs
- JsonReaderDelegator.cs
- ScriptModule.cs
- HiddenFieldPageStatePersister.cs
- WebRequestModuleElementCollection.cs
- WmlImageAdapter.cs
- SafeProcessHandle.cs
- Win32PrintDialog.cs
- ModelPerspective.cs
- WindowsAuthenticationEventArgs.cs
- ButtonColumn.cs
- ToolStripCollectionEditor.cs
- OleDbParameterCollection.cs
- AutoResizedEvent.cs