Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.ServiceModel.Routing / System / ServiceModel / Routing / ProcessRequestAsyncResult.cs / 1305376 / ProcessRequestAsyncResult.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.ServiceModel.Routing { using System; using System.Configuration; using System.Runtime; using System.ServiceModel.Channels; using System.ServiceModel.Dispatcher; using System.Threading; using System.Transactions; //using System.Security.Principal; class ProcessRequestAsyncResult: AsyncResult { static AsyncCompletion operationCallback = new AsyncCompletion(OperationCallback); RoutingService service; IRoutingClient currentClient; MessageRpc messageRpc; Message replyMessage; bool allCompletedSync; bool abortedRetry; public ProcessRequestAsyncResult(RoutingService service, Message message, AsyncCallback callback, object state) : base(callback, state) { this.allCompletedSync = true; this.service = service; this.messageRpc = new MessageRpc(message, OperationContext.Current, service.ChannelExtension.ImpersonationRequired); if (TD.RoutingServiceProcessingMessageIsEnabled()) { TD.RoutingServiceProcessingMessage(this.messageRpc.UniqueID, message.Headers.Action, this.messageRpc.OperationContext.EndpointDispatcher.EndpointAddress.Uri.ToString(), messageRpc.Transaction != null ? "True" : "False"); } try { EndpointNameMessageFilter.Set(this.messageRpc.Message.Properties, service.ChannelExtension.EndpointName); this.messageRpc.RouteToSingleEndpoint (this.service.RoutingConfig); } catch (MultipleFilterMatchesException matchesException) { // Wrap this exception with one that is more meaningful to users of RoutingService: throw FxTrace.Exception.AsError(new ConfigurationErrorsException(SR.ReqReplyMulticastNotSupported(this.messageRpc.OperationContext.Channel.LocalAddress), matchesException)); } while (this.StartProcessing()) { } } bool StartProcessing() { bool callAgain = false; SendOperation sendOperation = this.messageRpc.Operations[0]; this.currentClient = this.service.GetOrCreateClient (sendOperation.CurrentEndpoint, this.messageRpc.Impersonating); if (TD.RoutingServiceTransmittingMessageIsEnabled()) { TD.RoutingServiceTransmittingMessage(this.messageRpc.UniqueID, "0", this.currentClient.Key.ToString()); } try { if (messageRpc.Transaction != null && sendOperation.HasAlternate) { throw FxTrace.Exception.AsError(new ConfigurationErrorsException(SR.ErrorHandlingNotSupportedReqReplyTxn(this.messageRpc.OperationContext.Channel.LocalAddress))); } Message message; if (sendOperation.HasAlternate) { message = messageRpc.CreateBuffer().CreateMessage(); } else { message = messageRpc.Message; } sendOperation.PrepareMessage(message); IAsyncResult result = null; using (this.PrepareTransactionalCall(messageRpc.Transaction)) { IDisposable impersonationContext = null; try { //Perform the assignment in a finally block so it won't be interrupted asynchronously try { } finally { impersonationContext = messageRpc.PrepareCall(); } result = this.currentClient.BeginOperation(message, messageRpc.Transaction, this.PrepareAsyncCompletion(operationCallback), this); } finally { if (impersonationContext != null) { impersonationContext.Dispose(); } } } if (this.CheckSyncContinue(result)) { if (this.OperationComplete(result)) { this.Complete(this.allCompletedSync); } else { callAgain = true; } } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } if (!this.HandleClientOperationFailure(exception)) { throw; } callAgain = true; } return callAgain; } static bool OperationCallback(IAsyncResult result) { ProcessRequestAsyncResult thisPtr = (ProcessRequestAsyncResult )result.AsyncState; FxTrace.Trace.SetAndTraceTransfer(thisPtr.service.ChannelExtension.ActivityID, true); thisPtr.allCompletedSync = false; try { if (thisPtr.OperationComplete(result)) { return true; } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } if (!thisPtr.HandleClientOperationFailure(exception)) { throw; } } while (thisPtr.StartProcessing()) { } return false; } // Returns true if we're all done and can complete this AsyncResult now bool OperationComplete(IAsyncResult result) { bool completeSelf = false; Message responseMsg = this.currentClient.EndOperation(result); if (TD.RoutingServiceTransmitSucceededIsEnabled()) { TD.RoutingServiceTransmitSucceeded(this.messageRpc.UniqueID, "0", this.currentClient.Key.ToString()); } if (responseMsg == null || !responseMsg.IsFault) { if (TD.RoutingServiceSendingResponseIsEnabled()) { string action = (responseMsg != null) ? responseMsg.Headers.Action : string.Empty; TD.RoutingServiceSendingResponse(action); } } else { if (TD.RoutingServiceSendingFaultResponseIsEnabled()) { TD.RoutingServiceSendingFaultResponse(responseMsg.Headers.Action); } } this.replyMessage = responseMsg; completeSelf = true; if (TD.RoutingServiceCompletingTwoWayIsEnabled()) { TD.RoutingServiceCompletingTwoWay(null); } return completeSelf; } internal static Message End(IAsyncResult result) { ProcessRequestAsyncResult processRequest = AsyncResult.End >(result); return processRequest.replyMessage; } bool HandleClientOperationFailure(Exception exception) { SendOperation sendOperation = this.messageRpc.Operations[0]; if (TD.RoutingServiceTransmitFailedIsEnabled()) { TD.RoutingServiceTransmitFailed(sendOperation.CurrentEndpoint.ToString(), exception); } if (!(exception is CommunicationException || exception is TimeoutException)) { //We only move to backup for CommunicationExceptions and TimeoutExceptions return false; } if ((exception is CommunicationObjectAbortedException || exception is CommunicationObjectFaultedException) && !this.service.ChannelExtension.HasSession) { // Messages on a non sessionful channel share outbound connections and can // fail due to other messages failing on the same channel if (messageRpc.Transaction == null && !this.abortedRetry) { //No session and non transactional, retry the message 1 time (before moving to backup) this.abortedRetry = true; return true; } } if (sendOperation.TryMoveToAlternate(exception)) { if (TD.RoutingServiceMovedToBackupIsEnabled()) { TD.RoutingServiceMovedToBackup(messageRpc.UniqueID, "0", sendOperation.CurrentEndpoint.ToString()); } return true; } return false; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Exceptions.cs
- DiffuseMaterial.cs
- StorageMappingItemLoader.cs
- Label.cs
- SimpleHandlerBuildProvider.cs
- XmlWrappingReader.cs
- ScrollViewer.cs
- SamlSerializer.cs
- DataGridViewCheckBoxCell.cs
- RegexNode.cs
- DelegatingMessage.cs
- XPathParser.cs
- SmiRequestExecutor.cs
- HtmlWindow.cs
- UnionCodeGroup.cs
- ZoneLinkButton.cs
- CompilationRelaxations.cs
- ToolStripSeparatorRenderEventArgs.cs
- Label.cs
- ListViewUpdatedEventArgs.cs
- SessionStateUtil.cs
- WindowsClaimSet.cs
- WebPartMinimizeVerb.cs
- RotateTransform3D.cs
- StringAttributeCollection.cs
- HttpResponseHeader.cs
- TemplateBindingExtensionConverter.cs
- SetterBase.cs
- ComplexObject.cs
- DataExpression.cs
- PropVariant.cs
- HttpAsyncResult.cs
- SapiAttributeParser.cs
- CalloutQueueItem.cs
- CertificateManager.cs
- SqlDeflator.cs
- HashMembershipCondition.cs
- ValidatorCollection.cs
- FocusManager.cs
- UpdatePanelTrigger.cs
- DefaultShape.cs
- TrackingStringDictionary.cs
- WindowsTab.cs
- StringValidator.cs
- SoapSchemaImporter.cs
- VirtualizingPanel.cs
- DocumentPage.cs
- RootProfilePropertySettingsCollection.cs
- CalendarBlackoutDatesCollection.cs
- SystemNetHelpers.cs
- ProviderBase.cs
- StyleBamlRecordReader.cs
- Evidence.cs
- ManagedFilter.cs
- LongSumAggregationOperator.cs
- LazyInitializer.cs
- XhtmlTextWriter.cs
- PrintEvent.cs
- ObjectPersistData.cs
- SqlMethodAttribute.cs
- DataGridCaption.cs
- DateRangeEvent.cs
- ColorMatrix.cs
- UIElement3DAutomationPeer.cs
- HtmlInputHidden.cs
- CacheHelper.cs
- GradientBrush.cs
- XmlMapping.cs
- LogicalTreeHelper.cs
- WorkflowApplicationException.cs
- _AutoWebProxyScriptEngine.cs
- Scalars.cs
- WebZone.cs
- JoinSymbol.cs
- _UriSyntax.cs
- FreezableCollection.cs
- DesignerImageAdapter.cs
- BaseCAMarshaler.cs
- DataSourceControlBuilder.cs
- ConfigurationValidatorBase.cs
- SystemInfo.cs
- Debugger.cs
- HttpHandlerActionCollection.cs
- PagedDataSource.cs
- Brush.cs
- WebPartChrome.cs
- OdbcConnectionOpen.cs
- DbConnectionPoolOptions.cs
- ParserContext.cs
- IDQuery.cs
- EmptyEnumerable.cs
- ImageMapEventArgs.cs
- FilterElement.cs
- DataServiceContext.cs
- LineBreak.cs
- Int32Collection.cs
- MessageSecurityOverHttpElement.cs
- XMLUtil.cs
- FileUpload.cs
- BindValidationContext.cs