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
- CalendarDesigner.cs
- ReadWriteSpinLock.cs
- ISAPIRuntime.cs
- ResolveCompletedEventArgs.cs
- SchemaObjectWriter.cs
- OracleMonthSpan.cs
- PolyLineSegment.cs
- regiisutil.cs
- ConvertBinder.cs
- SiteMembershipCondition.cs
- AssemblyResourceLoader.cs
- EntryPointNotFoundException.cs
- CatalogZoneDesigner.cs
- DBConcurrencyException.cs
- Visual3D.cs
- BuildDependencySet.cs
- BufferModeSettings.cs
- PreservationFileReader.cs
- XslTransformFileEditor.cs
- validation.cs
- ClrPerspective.cs
- GridViewColumnHeader.cs
- CLRBindingWorker.cs
- StrokeRenderer.cs
- AnnotationStore.cs
- DataComponentGenerator.cs
- TreeView.cs
- TreeViewImageKeyConverter.cs
- UIElement3DAutomationPeer.cs
- ListControl.cs
- TraceSection.cs
- AutoCompleteStringCollection.cs
- DbModificationCommandTree.cs
- CriticalFinalizerObject.cs
- MouseActionValueSerializer.cs
- ReferentialConstraint.cs
- EmptyQuery.cs
- DataGridParentRows.cs
- Container.cs
- PackagePartCollection.cs
- ItemsChangedEventArgs.cs
- ScrollChrome.cs
- FunctionCommandText.cs
- Imaging.cs
- XmlElementAttribute.cs
- SrgsDocumentParser.cs
- PrintingPermission.cs
- FlowDocumentReader.cs
- DataGridViewCellFormattingEventArgs.cs
- PeerNearMe.cs
- CodeExpressionCollection.cs
- CriticalHandle.cs
- WebException.cs
- SpecularMaterial.cs
- FormsAuthenticationConfiguration.cs
- Stackframe.cs
- GridLength.cs
- ReceiveParametersContent.cs
- VisualStyleRenderer.cs
- SByteConverter.cs
- Types.cs
- HyperLinkColumn.cs
- CompiledRegexRunnerFactory.cs
- AspNetHostingPermission.cs
- DataBindingValueUIHandler.cs
- HostingPreferredMapPath.cs
- PerformanceCounterCategory.cs
- PointKeyFrameCollection.cs
- PtsHost.cs
- ProcessRequestArgs.cs
- VectorCollectionConverter.cs
- SqlWebEventProvider.cs
- WebPartConnectionCollection.cs
- MergablePropertyAttribute.cs
- CompositeDispatchFormatter.cs
- ListSortDescriptionCollection.cs
- UIInitializationException.cs
- ConfigurationSectionGroupCollection.cs
- EmbeddedMailObjectsCollection.cs
- XPathNavigatorKeyComparer.cs
- MessageEncoderFactory.cs
- GroupBoxAutomationPeer.cs
- GetPolicyDetailsRequest.cs
- ColorTransformHelper.cs
- CharUnicodeInfo.cs
- GPPOINT.cs
- AnnotationMap.cs
- TreeViewImageKeyConverter.cs
- SimpleWorkerRequest.cs
- SplitterPanelDesigner.cs
- COM2FontConverter.cs
- StaticTextPointer.cs
- X509Certificate.cs
- WebPartManager.cs
- GenericTypeParameterBuilder.cs
- SingleAnimationUsingKeyFrames.cs
- Group.cs
- XamlTreeBuilderBamlRecordWriter.cs
- MenuItem.cs
- InputMethodStateChangeEventArgs.cs