private void ServerScheduleOnReceivedMessage(NativeActivityContext executionContext, ReceiveMessageInstanceData instance) { System.ServiceModel.Channels.Message message = instance.CorrelationResponseContext.WorkflowOperationContext.Inputs[0] as System.ServiceModel.Channels.Message; this.Message.Set(executionContext, message); instance.CorrelationResponseContext.MessageVersion = ((System.ServiceModel.Channels.Message)instance.CorrelationResponseContext.WorkflowOperationContext.Inputs[0]).Version; CorrelationHandle ambientCorrelation = instance.GetAmbientCorrelation(executionContext); CorrelationHandle selectHandle = (this.CorrelatesWith == null) ? null : this.CorrelatesWith.Get(executionContext); MessagingActivityHelper.InitializeCorrelationHandles(executionContext, selectHandle, ambientCorrelation, this.correlationInitializers, instance.CorrelationResponseContext.WorkflowOperationContext.OperationContext.IncomingMessageProperties); CorrelationHandle explicitChannelCorrelation = CorrelationHandle.GetExplicitChannelCorrelation(executionContext, this.correlationInitializers); if (this.IsOneWay) { if (explicitChannelCorrelation != null) { throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activities.SR.RequestReplyHandleShouldNotBePresentForOneWay)); } if (this.NoPersistHandle != null) { System.Activities.NoPersistHandle handle4 = this.NoPersistHandle.Get(executionContext); if (handle4 != null) { handle4.Enter(executionContext); } } } else if (explicitChannelCorrelation != null) { if (!explicitChannelCorrelation.TryRegisterResponseContext(executionContext, instance.CorrelationResponseContext)) { throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activities.SR.TryRegisterRequestContextFailed)); } } else if (!ambientCorrelation.TryRegisterResponseContext(executionContext, instance.CorrelationResponseContext)) { throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activities.SR.ReceiveMessageNeedsToPairWithSendMessageForTwoWayContract(this.OperationName))); } if (instance.CorrelationCallbackContext != null) { CorrelationHandle explicitCallbackCorrelation = CorrelationHandle.GetExplicitCallbackCorrelation(executionContext, this.correlationInitializers); if (explicitCallbackCorrelation == null) { explicitCallbackCorrelation = ambientCorrelation; } if (explicitCallbackCorrelation != null) { explicitCallbackCorrelation.CallbackContext = instance.CorrelationCallbackContext; } } this.FinalizeScheduleOnReceivedMessage(executionContext, instance); }
protected override void Execute(NativeActivityContext executionContext) { CorrelationRequestContext context; CorrelationHandle handle = (this.CorrelatesWith == null) ? null : this.CorrelatesWith.Get(executionContext); bool flag = false; CorrelationHandle ambientCorrelation = null; if (handle == null) { ambientCorrelation = executionContext.Properties.Find(CorrelationHandle.StaticExecutionPropertyName) as CorrelationHandle; flag = true; if (ambientCorrelation != null) { handle = ambientCorrelation; } } if ((handle != null) && handle.TryAcquireRequestContext(executionContext, out context)) { ReceiveMessageInstanceData instance = new ReceiveMessageInstanceData(context); if (flag) { instance.SetAmbientCorrelation(ambientCorrelation); } this.ClientScheduleOnReceivedMessage(executionContext, instance); } else { if (ambientCorrelation == null) { ambientCorrelation = executionContext.Properties.Find(CorrelationHandle.StaticExecutionPropertyName) as CorrelationHandle; } if ((!this.IsOneWay && (ambientCorrelation == null)) && (CorrelationHandle.GetExplicitChannelCorrelation(executionContext, this.correlationInitializers) == null)) { throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activities.SR.ReceiveMessageNeedsToPairWithSendMessageForTwoWayContract(this.OperationName))); } BookmarkScope scope = (handle != null) ? handle.EnsureBookmarkScope(executionContext) : executionContext.DefaultBookmarkScope; if (this.onMessageBookmarkCallback == null) { this.onMessageBookmarkCallback = new BookmarkCallback(this.OnMessage); } executionContext.CreateBookmark(this.OperationBookmarkName, this.onMessageBookmarkCallback, scope); } }