internal void SetCurrent(ref MessageRpc rpc) { Transaction current = rpc.Transaction.Current; if (current == null) { DiagnosticUtility.FailFast("we should never get here with a requestTransaction null"); } lock (this.mutex) { if (this.current == null) { this.current = current; } else if (this.current != current) { this.waiting = current; this.paused = rpc.Pause(); } else { rpc.Transaction.Current = this.current; } } }
public AcknowledgementCompleteAsyncResult( ReceiveContext receiveContext, TimeSpan timeout, ref MessageRpc rpc, Transaction transaction, AsyncCallback callback, object state) : base(callback, state) { this.receiveContext = receiveContext; this.currentTransaction = transaction; this.channelHandler = rpc.channelHandler; this.resumableRPC = rpc.Pause(); bool completeThrew = true; try { bool completed = this.Complete(timeout); completeThrew = false; if (completed) { this.resumableRPC = null; rpc.UnPause(); this.Complete(true); } } finally { if (completeThrew) { rpc.UnPause(); } } }
// ........................................................................................................ internal void SetCurrent(ref MessageRpc rpc) { Transaction requestTransaction = rpc.Transaction.Current; if (!(requestTransaction != null)) { // tx processing requires failfast when state is inconsistent DiagnosticUtility.FailFast("we should never get here with a requestTransaction null"); } lock (this.mutex) { if (this.current == null) { this.current = requestTransaction; } else if (this.current != requestTransaction) { this.waiting = requestTransaction; this.paused = rpc.Pause(); } else { rpc.Transaction.Current = this.current; //rpc.Transaction.Current should get the dependent clone } } }
private void BindCore(ref MessageRpc rpc, bool startOperation) { SynchronizationContext syncContext = this.GetSyncContext(rpc.InstanceContext); if (syncContext != null) { IResumeMessageRpc state = rpc.Pause(); if (startOperation) { syncContext.OperationStarted(); syncContext.Post(this.ThreadAffinityStartCallbackDelegate, state); } else { syncContext.Post(this.ThreadAffinityEndCallbackDelegate, state); } } else if (rpc.SwitchedThreads) { IResumeMessageRpc rpc3 = rpc.Pause(); ActionItem.Schedule(CleanThreadCallbackDelegate, rpc3); } }
private void BindCore(ref MessageRpc rpc, bool startOperation) { SynchronizationContext syncContext = GetSyncContext(rpc.InstanceContext); if (syncContext != null) { IResumeMessageRpc resume = rpc.Pause(); if (startOperation) { syncContext.OperationStarted(); syncContext.Post(ThreadAffinityStartCallbackDelegate, resume); } else { syncContext.Post(ThreadAffinityEndCallbackDelegate, resume); } } else if (rpc.SwitchedThreads) { IResumeMessageRpc resume = rpc.Pause(); ActionItem.Schedule(ThreadBehavior.CleanThreadCallbackDelegate, resume); } }
private void BeginReply(ref MessageRpc rpc) { bool success = false; try { IResumeMessageRpc resume = rpc.Pause(); rpc.AsyncResult = rpc.RequestContext.BeginReply(rpc.Reply, rpc.ReplyTimeoutHelper.RemainingTime(), s_onReplyCompleted, resume); success = true; if (rpc.AsyncResult.CompletedSynchronously) { rpc.UnPause(); } } catch (CommunicationException e) { _error.HandleError(e); } catch (TimeoutException e) { _error.HandleError(e); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } if (!_error.HandleError(e)) { rpc.RequestContextThrewOnReply = true; rpc.CanSendReply = false; } } finally { if (!success) { rpc.UnPause(); } } }
internal void InvokeBegin(ref MessageRpc rpc) { if (rpc.Error == null) { object target = rpc.Instance; this.DeserializeInputs(ref rpc); this.InspectInputs(ref rpc); ValidateMustUnderstand(ref rpc); IAsyncResult result; bool isBeginSuccessful = false; IResumeMessageRpc resumeRpc = rpc.Pause(); try { result = Invoker.InvokeBegin(target, rpc.InputParameters, invokeCallback, resumeRpc); isBeginSuccessful = true; } finally { if (!isBeginSuccessful) { rpc.UnPause(); } } 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; } } }
internal void LockInstance(ref MessageRpc rpc) { if (this.mode != ConcurrencyMode.Multiple) { ConcurrencyInstanceContextFacet concurrency = rpc.InstanceContext.Concurrency; lock (rpc.InstanceContext.ThisLock) { if (!concurrency.Locked) { concurrency.Locked = true; } else { MessageRpcWaiter waiter = new MessageRpcWaiter(rpc.Pause()); concurrency.EnqueueNewMessage(waiter); } } if (this.mode == ConcurrencyMode.Reentrant) { rpc.OperationContext.IsServiceReentrant = true; } } }
private void BeginReply(ref MessageRpc rpc) { bool flag = false; try { IResumeMessageRpc state = rpc.Pause(); rpc.AsyncResult = rpc.RequestContext.BeginReply(rpc.Reply, rpc.ReplyTimeoutHelper.RemainingTime(), onReplyCompleted, state); flag = true; if (rpc.AsyncResult.CompletedSynchronously) { rpc.UnPause(); } } catch (CommunicationException exception) { this.error.HandleError(exception); } catch (TimeoutException exception2) { this.error.HandleError(exception2); } catch (Exception exception3) { if (Fx.IsFatal(exception3)) { throw; } if (DiagnosticUtility.ShouldTraceError) { TraceUtility.TraceEvent(TraceEventType.Error, 0x80034, System.ServiceModel.SR.GetString("TraceCodeServiceOperationExceptionOnReply"), this, exception3); } if (!this.error.HandleError(exception3)) { rpc.RequestContextThrewOnReply = true; rpc.CanSendReply = false; } } finally { if (!flag) { rpc.UnPause(); } } }
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); } } }
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 (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) { 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); } } }
private void BeginFinalizeCorrelation(ref MessageRpc rpc) { CorrelationCallbackMessageProperty property; Message reply = rpc.Reply; if ((((reply != null) && (rpc.Error == null)) && (((rpc.transaction == null) || (rpc.transaction.Current == null)) || (rpc.transaction.Current.TransactionInformation.Status == TransactionStatus.Active))) && CorrelationCallbackMessageProperty.TryGet(reply, out property)) { if (property.IsFullyDefined) { bool flag = false; try { try { rpc.RequestContextThrewOnReply = true; rpc.CorrelationCallback = property; IResumeMessageRpc state = rpc.Pause(); rpc.AsyncResult = rpc.CorrelationCallback.BeginFinalizeCorrelation(reply, rpc.ReplyTimeoutHelper.RemainingTime(), onFinalizeCorrelationCompleted, state); flag = true; if (rpc.AsyncResult.CompletedSynchronously) { rpc.UnPause(); } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } if (!this.error.HandleError(exception)) { rpc.CorrelationCallback = null; rpc.CanSendReply = false; } } return; } finally { if (!flag) { rpc.UnPause(); } } } rpc.CorrelationCallback = new RpcCorrelationCallbackMessageProperty(property, this, ref rpc); reply.Properties[CorrelationCallbackMessageProperty.Name] = rpc.CorrelationCallback; } }
void BeginFinalizeCorrelation(ref MessageRpc rpc) { Message reply = rpc.Reply; if (reply != null && rpc.Error == null) { if (rpc.transaction != null && rpc.transaction.Current != null && rpc.transaction.Current.TransactionInformation.Status != TransactionStatus.Active) { return; } CorrelationCallbackMessageProperty callback; if (CorrelationCallbackMessageProperty.TryGet(reply, out callback)) { if (callback.IsFullyDefined) { bool success = false; try { rpc.RequestContextThrewOnReply = true; rpc.CorrelationCallback = callback; IResumeMessageRpc resume = rpc.Pause(); rpc.AsyncResult = rpc.CorrelationCallback.BeginFinalizeCorrelation(reply, rpc.ReplyTimeoutHelper.RemainingTime(), onFinalizeCorrelationCompleted, resume); success = true; if (rpc.AsyncResult.CompletedSynchronously) { rpc.UnPause(); } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } if (!this.error.HandleError(e)) { rpc.CorrelationCallback = null; rpc.CanSendReply = false; } } finally { if (!success) { rpc.UnPause(); } } } else { rpc.CorrelationCallback = new RpcCorrelationCallbackMessageProperty(callback, this, ref rpc); reply.Properties[CorrelationCallbackMessageProperty.Name] = rpc.CorrelationCallback; } } } }
bool AcquireDynamicInstanceContextCore(ref MessageRpc rpc) { bool success = rpc.InstanceContext.QuotaThrottle.Acquire(rpc.Pause()); if (success) { rpc.UnPause(); } return success; }
void BeginReply(ref MessageRpc rpc) { bool success = false; try { IResumeMessageRpc resume = rpc.Pause(); rpc.AsyncResult = rpc.RequestContext.BeginReply(rpc.Reply, rpc.ReplyTimeoutHelper.RemainingTime(), onReplyCompleted, resume); success = true; if (rpc.AsyncResult.CompletedSynchronously) { rpc.UnPause(); } } catch (CommunicationException e) { this.error.HandleError(e); } catch (TimeoutException e) { this.error.HandleError(e); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } if (DiagnosticUtility.ShouldTraceError) { TraceUtility.TraceEvent(System.Diagnostics.TraceEventType.Error, TraceCode.ServiceOperationExceptionOnReply, SR.GetString(SR.TraceCodeServiceOperationExceptionOnReply), this, e); } if (!this.error.HandleError(e)) { rpc.RequestContextThrewOnReply = true; rpc.CanSendReply = false; } } finally { if (!success) { rpc.UnPause(); } } }
private bool AcquireDynamicInstanceContextCore(ref MessageRpc rpc) { bool flag = rpc.InstanceContext.QuotaThrottle.Acquire(rpc.Pause()); if (flag) { rpc.UnPause(); } return flag; }