public ServiceOperationAsyncResult(IOperationInvoker innerInvoker, WorkflowServiceInstance durableInstance, object[] inputs, OperationContext operationContext, Transaction currentTransaction, IInvokeReceivedNotification notification, AsyncCallback callback, object state) : base(callback, state) { this.durableInstance = durableInstance; this.operationContext = operationContext; this.inputs = inputs; this.innerInvoker = innerInvoker; this.currentTransaction = currentTransaction; this.notification = notification; if (innerInvoker == null) { throw Fx.AssertAndThrow("Cannot reach this path without innerInvoker"); } if (this.innerInvoker.IsSynchronous) { TransactionScope scope = Fx.CreateTransactionScope(this.currentTransaction); try { using (new OperationContextScopeHelper(this.operationContext)) { IManualConcurrencyOperationInvoker invoker = this.innerInvoker as IManualConcurrencyOperationInvoker; if (invoker != null) { this.returnValue = invoker.Invoke(this.durableInstance, this.inputs, this.notification, out this.outputs); } else { this.returnValue = this.innerInvoker.Invoke(this.durableInstance, this.inputs, out this.outputs); } } } finally { Fx.CompleteTransactionScope(ref scope); } base.Complete(true); } else { IAsyncResult result; using (base.PrepareTransactionalCall(this.currentTransaction)) { using (new OperationContextScopeHelper(this.operationContext)) { IManualConcurrencyOperationInvoker invoker2 = this.innerInvoker as IManualConcurrencyOperationInvoker; if (invoker2 != null) { result = invoker2.InvokeBegin(this.durableInstance, this.inputs, this.notification, base.PrepareAsyncCompletion(handleEndInvoke), this); } else { result = this.innerInvoker.InvokeBegin(this.durableInstance, this.inputs, base.PrepareAsyncCompletion(handleEndInvoke), this); } } } if (base.SyncContinue(result)) { base.Complete(true); } } }
internal void InvokeBegin(ref MessageRpc rpc) { if (rpc.Error == null) { try { this.InitializeCallContext(ref rpc); object instance = rpc.Instance; this.DeserializeInputs(ref rpc); this.InspectInputs(ref rpc); this.ValidateMustUnderstand(ref rpc); IAsyncResult result = null; IDisposable impersonationContext = null; IPrincipal originalPrincipal = null; bool isThreadPrincipalSet = false; bool flag2 = this.Parent.IsConcurrent(ref rpc); try { if (this.parent.SecurityImpersonation != null) { this.parent.SecurityImpersonation.StartImpersonation(ref rpc, out impersonationContext, out originalPrincipal, out isThreadPrincipalSet); } IManualConcurrencyOperationInvoker invoker = this.Invoker as IManualConcurrencyOperationInvoker; if (this.isSynchronous) { if ((invoker != null) && flag2) { if (this.bufferedReceiveEnabled) { rpc.OperationContext.IncomingMessageProperties.Add(BufferedReceiveMessageProperty.Name, new BufferedReceiveMessageProperty(ref rpc)); } rpc.ReturnParameter = invoker.Invoke(instance, rpc.InputParameters, rpc.InvokeNotification, out rpc.OutputParameters); } else { rpc.ReturnParameter = this.Invoker.Invoke(instance, rpc.InputParameters, out rpc.OutputParameters); } } else { bool flag3 = false; if (((invoker != null) && flag2) && this.bufferedReceiveEnabled) { rpc.OperationContext.IncomingMessageProperties.Add(BufferedReceiveMessageProperty.Name, new BufferedReceiveMessageProperty(ref rpc)); } IResumeMessageRpc state = rpc.Pause(); try { if ((invoker != null) && flag2) { result = invoker.InvokeBegin(instance, rpc.InputParameters, rpc.InvokeNotification, invokeCallback, state); } else { result = this.Invoker.InvokeBegin(instance, rpc.InputParameters, invokeCallback, state); } flag3 = true; } finally { if (!flag3) { rpc.UnPause(); } } } } finally { try { if (this.parent.SecurityImpersonation != null) { this.parent.SecurityImpersonation.StopImpersonation(ref rpc, impersonationContext, originalPrincipal, isThreadPrincipalSet); } } catch { string message = null; try { message = System.ServiceModel.SR.GetString("SFxRevertImpersonationFailed0"); } finally { DiagnosticUtility.FailFast(message); } } } if (this.isSynchronous) { this.InspectOutputs(ref rpc); this.SerializeOutputs(ref rpc); } else { if (result == null) { throw TraceUtility.ThrowHelperError(new ArgumentNullException("IOperationInvoker.BeginDispatch"), rpc.Request); } if (result.CompletedSynchronously) { rpc.UnPause(); rpc.AsyncResult = result; } } } catch { throw; } finally { this.UninitializeCallContext(ref rpc); } } }
internal void InvokeBegin(ref MessageRpc rpc) { if (rpc.Error == null) { try { this.InitializeCallContext(ref rpc); object target = rpc.Instance; this.DeserializeInputs(ref rpc); this.InspectInputs(ref rpc); ValidateMustUnderstand(ref rpc); IAsyncResult result = null; IDisposable impersonationContext = null; IPrincipal originalPrincipal = null; bool isThreadPrincipalSet = false; bool isConcurrent = this.Parent.IsConcurrent(ref rpc); try { if (this.parent.RequireClaimsPrincipalOnOperationContext) { SetClaimsPrincipalToOperationContext(rpc); } if (this.parent.SecurityImpersonation != null) { this.parent.SecurityImpersonation.StartImpersonation(ref rpc, out impersonationContext, out originalPrincipal, out isThreadPrincipalSet); } IManualConcurrencyOperationInvoker manualInvoker = this.Invoker as IManualConcurrencyOperationInvoker; if (DS.OperationInvokerIsEnabled()) { DS.InvokeOperationStart(this.Invoker.GetType(), Stopwatch.GetTimestamp()); } if (this.isSynchronous) { if (manualInvoker != null && isConcurrent) { if (this.bufferedReceiveEnabled) { rpc.OperationContext.IncomingMessageProperties.Add( BufferedReceiveMessageProperty.Name, new BufferedReceiveMessageProperty(ref rpc)); } rpc.ReturnParameter = manualInvoker.Invoke(target, rpc.InputParameters, rpc.InvokeNotification, out rpc.OutputParameters); } else { rpc.ReturnParameter = this.Invoker.Invoke(target, rpc.InputParameters, out rpc.OutputParameters); } } else { bool isBeginSuccessful = false; if (manualInvoker != null && isConcurrent && this.bufferedReceiveEnabled) { // This will modify the rpc, it has to be done before rpc.Pause // since IResumeMessageRpc implementation keeps reference of rpc. // This is to ensure consistent rpc whether or not InvokeBegin completed // synchronously or asynchronously. rpc.OperationContext.IncomingMessageProperties.Add( BufferedReceiveMessageProperty.Name, new BufferedReceiveMessageProperty(ref rpc)); } IResumeMessageRpc resumeRpc = rpc.Pause(); try { if (manualInvoker != null && isConcurrent) { result = manualInvoker.InvokeBegin(target, rpc.InputParameters, rpc.InvokeNotification, invokeCallback, resumeRpc); } else { result = this.Invoker.InvokeBegin(target, rpc.InputParameters, invokeCallback, resumeRpc); } isBeginSuccessful = true; // if the call above actually went async, then responsibility to call // ProcessMessage{6,7,Cleanup} has been transferred to InvokeCallback } finally { if (!isBeginSuccessful) { rpc.UnPause(); } } } } finally { try { if (this.parent.SecurityImpersonation != null) { this.parent.SecurityImpersonation.StopImpersonation(ref rpc, impersonationContext, originalPrincipal, isThreadPrincipalSet); } } #pragma warning suppress 56500 // covered by FxCOP catch { string message = null; try { message = SR.GetString(SR.SFxRevertImpersonationFailed0); } finally { DiagnosticUtility.FailFast(message); } } if (this.isSynchronous && DS.OperationInvokerIsEnabled()) { DS.InvokeOperationStop(Stopwatch.GetTimestamp()); } } if (this.isSynchronous) { this.InspectOutputs(ref rpc); this.SerializeOutputs(ref rpc); } else { if (result == null) { throw TraceUtility.ThrowHelperError(new ArgumentNullException("IOperationInvoker.BeginDispatch"), rpc.Request); } if (result.CompletedSynchronously) { // if the async call completed synchronously, then the responsibility to call // ProcessMessage{6,7,Cleanup} still remains on this thread rpc.UnPause(); rpc.AsyncResult = result; } } } #pragma warning suppress 56500 // covered by FxCOP catch { throw; } // Make sure user Exception filters are not impersonated. finally { this.UninitializeCallContext(ref rpc); } } }