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
- PackWebRequestFactory.cs
- PropertyChangeTracker.cs
- EventsTab.cs
- MediaTimeline.cs
- TextPointer.cs
- XmlCustomFormatter.cs
- VersionPair.cs
- ValidatingReaderNodeData.cs
- BreakRecordTable.cs
- ClientBuildManager.cs
- WindowsTreeView.cs
- Literal.cs
- SecurityTokenParameters.cs
- ELinqQueryState.cs
- DbFunctionCommandTree.cs
- _TLSstream.cs
- DataGridCommandEventArgs.cs
- WhereQueryOperator.cs
- GridErrorDlg.cs
- XmlWrappingReader.cs
- HighlightComponent.cs
- Config.cs
- ObjectDataSourceDisposingEventArgs.cs
- KeyGesture.cs
- OrderByQueryOptionExpression.cs
- PeerCollaboration.cs
- BindingManagerDataErrorEventArgs.cs
- EdgeModeValidation.cs
- LinkedResource.cs
- CorrelationManager.cs
- TextParaLineResult.cs
- OciEnlistContext.cs
- Rect3D.cs
- Label.cs
- EntityDataSourceWizardForm.cs
- MultilineStringEditor.cs
- StringBuilder.cs
- SessionParameter.cs
- SafeNativeMethods.cs
- ScrollContentPresenter.cs
- ServiceMetadataBehavior.cs
- Publisher.cs
- TemplateApplicationHelper.cs
- _AutoWebProxyScriptWrapper.cs
- GenericEnumerator.cs
- CodeSnippetExpression.cs
- AddingNewEventArgs.cs
- PeerTransportListenAddressConverter.cs
- QueryReaderSettings.cs
- TypeNameConverter.cs
- Brush.cs
- TextBounds.cs
- InboundActivityHelper.cs
- DeflateStreamAsyncResult.cs
- XmlNode.cs
- StrokeIntersection.cs
- CommandHelper.cs
- ExpressionBuilder.cs
- XXXInfos.cs
- RSAOAEPKeyExchangeDeformatter.cs
- RadioButtonBaseAdapter.cs
- ActivationArguments.cs
- WinFormsComponentEditor.cs
- Binding.cs
- TdsParserStateObject.cs
- PipelineModuleStepContainer.cs
- ASCIIEncoding.cs
- ClientUtils.cs
- FormViewInsertedEventArgs.cs
- TableLayoutPanelCellPosition.cs
- GetPageCompletedEventArgs.cs
- MsmqProcessProtocolHandler.cs
- ReadContentAsBinaryHelper.cs
- DataGridViewRowStateChangedEventArgs.cs
- UnsafeNativeMethods.cs
- PointValueSerializer.cs
- ParallelEnumerable.cs
- PackageFilter.cs
- CellPartitioner.cs
- DescendantBaseQuery.cs
- SafeCryptoHandles.cs
- BindingList.cs
- ClosableStream.cs
- CollectionDataContractAttribute.cs
- Baml2006KeyRecord.cs
- SqlCacheDependencySection.cs
- MatrixTransform.cs
- SerializationObjectManager.cs
- PageClientProxyGenerator.cs
- ExtendedProtectionPolicyTypeConverter.cs
- ObjectMemberMapping.cs
- CheckBoxList.cs
- XmlBinaryReader.cs
- RecommendedAsConfigurableAttribute.cs
- oledbmetadatacollectionnames.cs
- CompositionDesigner.cs
- ArrangedElementCollection.cs
- TimeSpanStorage.cs
- DataKey.cs
- StringFreezingAttribute.cs