| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Collections.ObjectModel; |
| | | 6 | | using System.Diagnostics; |
| | | 7 | | using System.Threading; |
| | | 8 | | using System.Threading.Tasks; |
| | | 9 | | using System.Xml; |
| | | 10 | | using CoreWCF.Channels; |
| | | 11 | | using CoreWCF.Runtime; |
| | | 12 | | |
| | | 13 | | namespace CoreWCF.Dispatcher |
| | | 14 | | { |
| | | 15 | | internal delegate Task<MessageRpc> MessageRpcProcessor(MessageRpc rpc); |
| | | 16 | | |
| | | 17 | | internal delegate Task MessageRpcErrorHandler(MessageRpc rpc); |
| | | 18 | | |
| | | 19 | | // TODO: Pool MessageRpc objects. These are zero cost on .NET Framework as it's a struct but passing things by ref i |
| | | 20 | | // when using async/await. This causes an allocation per request so pool them to remove that allocation. |
| | | 21 | | internal class MessageRpc |
| | | 22 | | { |
| | | 23 | | internal readonly ServiceChannel Channel; |
| | | 24 | | internal readonly ChannelHandler ChannelHandler; |
| | | 25 | | internal readonly object[] Correlation; |
| | | 26 | | internal readonly ServiceHostBase Host; |
| | | 27 | | internal readonly OperationContext OperationContext; |
| | | 28 | | //internal ServiceModelActivity Activity; |
| | | 29 | | internal Guid ResponseActivityId; |
| | | 30 | | internal IAsyncResult AsyncResult; |
| | | 31 | | internal Task TaskResult; |
| | | 32 | | internal bool CanSendReply; |
| | | 33 | | internal bool SuccessfullySendReply; |
| | | 34 | | internal object[] InputParameters; |
| | | 35 | | internal object[] OutputParameters; |
| | | 36 | | internal object ReturnParameter; |
| | | 37 | | internal bool ParametersDisposed; |
| | | 38 | | internal bool DidDeserializeRequestBody; |
| | | 39 | | //internal TransactionMessageProperty TransactionMessageProperty; |
| | | 40 | | //internal TransactedBatchContext TransactedBatchContext; |
| | | 41 | | internal Exception Error; |
| | | 42 | | internal MessageRpcErrorHandler ErrorProcessor; |
| | | 43 | | internal ErrorHandlerFaultInfo FaultInfo; |
| | | 44 | | internal bool HasSecurityContext; |
| | | 45 | | internal object Instance; |
| | | 46 | | internal bool MessageRpcOwnsInstanceContextThrottle; |
| | | 47 | | internal MessageRpcProcessor AsyncProcessor; |
| | | 48 | | internal Collection<MessageHeaderInfo> NotUnderstoodHeaders; |
| | | 49 | | internal DispatchOperationRuntime Operation; |
| | | 50 | | internal Message Request; |
| | | 51 | | internal RequestContext RequestContext; |
| | | 52 | | internal bool RequestContextThrewOnReply; |
| | | 53 | | internal UniqueId RequestID; |
| | | 54 | | internal Message Reply; |
| | | 55 | | internal TimeoutHelper ReplyTimeoutHelper; |
| | | 56 | | internal RequestReplyCorrelator.ReplyToInfo ReplyToInfo; |
| | | 57 | | internal MessageVersion RequestVersion; |
| | | 58 | | internal ServiceSecurityContext SecurityContext; |
| | | 59 | | internal InstanceContext InstanceContext; |
| | | 60 | | internal bool SuccessfullyBoundInstance; |
| | | 61 | | internal bool SuccessfullyIncrementedActivity; |
| | | 62 | | internal bool SuccessfullyLockedInstance; |
| | | 63 | | internal /* ReceiveContextRPCFacet */ ReceiveContext ReceiveContext; |
| | | 64 | | //internal TransactionRpcFacet transaction; |
| | | 65 | | //internal IAspNetMessageProperty HostingProperty; |
| | | 66 | | //internal MessageRpcInvokeNotification InvokeNotification; |
| | | 67 | | //internal EventTraceActivity EventTraceActivity; |
| | | 68 | | internal bool _processCallReturned; |
| | | 69 | | private bool _isInstanceContextSingleton; |
| | | 70 | | private SignalGate<IAsyncResult> _invokeContinueGate; |
| | | 71 | | |
| | 2538 | 72 | | internal MessageRpc(RequestContext requestContext, Message request, DispatchOperationRuntime operation, |
| | 2538 | 73 | | ServiceChannel channel, ServiceHostBase host, ChannelHandler channelHandler, bool cleanThread, |
| | 2538 | 74 | | OperationContext operationContext, InstanceContext instanceContext/*, EventTraceActivity eventTraceActivity* |
| | | 75 | | { |
| | | 76 | | Fx.Assert((operationContext != null), "correwcf.Dispatcher.MessageRpc.MessageRpc(), operationContext == null |
| | | 77 | | // TODO: ChannelHandler supplied an ErrorHandler, need to supply this some other way. |
| | | 78 | | //Fx.Assert(channelHandler != null, "System.ServiceModel.Dispatcher.MessageRpc.MessageRpc(), channelHandler |
| | | 79 | | |
| | | 80 | | //this.Activity = null; |
| | | 81 | | //this.EventTraceActivity = eventTraceActivity; |
| | 2538 | 82 | | AsyncResult = null; |
| | 2538 | 83 | | TaskResult = null; |
| | 2538 | 84 | | CanSendReply = true; |
| | 2538 | 85 | | Channel = channel; |
| | 2538 | 86 | | ChannelHandler = channelHandler; |
| | 2538 | 87 | | Correlation = EmptyArray.Allocate(operation.Parent.CorrelationCount); |
| | 2538 | 88 | | DidDeserializeRequestBody = false; |
| | 2538 | 89 | | Error = null; |
| | 2538 | 90 | | ErrorProcessor = null; |
| | 2538 | 91 | | FaultInfo = new ErrorHandlerFaultInfo(request.Version.Addressing.DefaultFaultAction); |
| | 2538 | 92 | | HasSecurityContext = false; |
| | 2538 | 93 | | Host = host; |
| | 2538 | 94 | | Instance = null; |
| | 2538 | 95 | | AsyncProcessor = null; |
| | 2538 | 96 | | NotUnderstoodHeaders = null; |
| | 2538 | 97 | | Operation = operation; |
| | 2538 | 98 | | OperationContext = operationContext; |
| | 2538 | 99 | | IsPaused = false; |
| | 2538 | 100 | | ParametersDisposed = false; |
| | 2538 | 101 | | ReceiveContext = null; |
| | 2538 | 102 | | Request = request; |
| | 2538 | 103 | | RequestContext = requestContext; |
| | 2538 | 104 | | RequestContextThrewOnReply = false; |
| | 2538 | 105 | | SuccessfullySendReply = false; |
| | 2538 | 106 | | RequestVersion = request.Version; |
| | 2538 | 107 | | Reply = null; |
| | 2538 | 108 | | ReplyTimeoutHelper = new TimeoutHelper(); |
| | 2538 | 109 | | SecurityContext = null; |
| | 2538 | 110 | | InstanceContext = instanceContext; |
| | 2538 | 111 | | SuccessfullyBoundInstance = false; |
| | 2538 | 112 | | SuccessfullyIncrementedActivity = false; |
| | 2538 | 113 | | SuccessfullyLockedInstance = false; |
| | 2538 | 114 | | SwitchedThreads = !cleanThread; |
| | | 115 | | //this.transaction = null; |
| | 2538 | 116 | | InputParameters = null; |
| | 2538 | 117 | | OutputParameters = null; |
| | 2538 | 118 | | ReturnParameter = null; |
| | 2538 | 119 | | _isInstanceContextSingleton = InstanceContextProviderBase.IsProviderSingleton(Channel.DispatchRuntime.Instan |
| | 2538 | 120 | | _invokeContinueGate = null; |
| | | 121 | | |
| | 2538 | 122 | | if (!operation.IsOneWay && !operation.Parent.ManualAddressing) |
| | | 123 | | { |
| | 683 | 124 | | RequestID = request.Headers.MessageId; |
| | 683 | 125 | | ReplyToInfo = new RequestReplyCorrelator.ReplyToInfo(request); |
| | | 126 | | } |
| | | 127 | | else |
| | | 128 | | { |
| | 1855 | 129 | | RequestID = null; |
| | 1855 | 130 | | ReplyToInfo = new RequestReplyCorrelator.ReplyToInfo(); |
| | | 131 | | } |
| | | 132 | | |
| | | 133 | | //if (DiagnosticUtility.ShouldUseActivity) |
| | | 134 | | //{ |
| | | 135 | | // this.Activity = TraceUtility.ExtractActivity(this.Request); |
| | | 136 | | //} |
| | | 137 | | |
| | | 138 | | //if (DiagnosticUtility.ShouldUseActivity || TraceUtility.ShouldPropagateActivity) |
| | | 139 | | //{ |
| | | 140 | | // this.ResponseActivityId = ActivityIdHeader.ExtractActivityId(this.Request); |
| | | 141 | | //} |
| | | 142 | | //else |
| | | 143 | | //{ |
| | 2538 | 144 | | ResponseActivityId = Guid.Empty; |
| | | 145 | | //} |
| | | 146 | | |
| | | 147 | | //if (this.EventTraceActivity == null && FxTrace.Trace.IsEnd2EndActivityTracingEnabled) |
| | | 148 | | //{ |
| | | 149 | | // if (this.Request != null) |
| | | 150 | | // { |
| | | 151 | | // this.EventTraceActivity = EventTraceActivityHelper.TryExtractActivity(this.Request, true); |
| | | 152 | | // } |
| | | 153 | | //} |
| | 2538 | 154 | | } |
| | | 155 | | |
| | 2538 | 156 | | internal bool IsPaused { get; private set; } |
| | | 157 | | |
| | 0 | 158 | | internal bool SwitchedThreads { get; } |
| | | 159 | | |
| | | 160 | | internal bool IsInstanceContextSingleton |
| | | 161 | | { |
| | | 162 | | set |
| | | 163 | | { |
| | 0 | 164 | | _isInstanceContextSingleton = value; |
| | 0 | 165 | | } |
| | | 166 | | } |
| | | 167 | | |
| | | 168 | | //internal TransactionRpcFacet Transaction |
| | | 169 | | //{ |
| | | 170 | | // get |
| | | 171 | | // { |
| | | 172 | | // if (this.transaction == null) |
| | | 173 | | // { |
| | | 174 | | // this.transaction = new TransactionRpcFacet(ref this); |
| | | 175 | | // } |
| | | 176 | | // return this.transaction; |
| | | 177 | | // } |
| | | 178 | | //} |
| | | 179 | | |
| | | 180 | | internal async ValueTask AbortAsync() |
| | | 181 | | { |
| | 0 | 182 | | await AbortRequestContextAsync(); |
| | 0 | 183 | | AbortChannel(); |
| | 0 | 184 | | AbortInstanceContext(); |
| | 0 | 185 | | } |
| | | 186 | | |
| | | 187 | | private async ValueTask AbortRequestContextAsync(RequestContext requestContext) |
| | | 188 | | { |
| | | 189 | | try |
| | | 190 | | { |
| | 54 | 191 | | requestContext.Abort(); |
| | | 192 | | |
| | 54 | 193 | | /* ReceiveContextRPCFacet */ ReceiveContext receiveContext = ReceiveContext; |
| | | 194 | | |
| | 54 | 195 | | if (receiveContext != null) |
| | | 196 | | { |
| | 53 | 197 | | ReceiveContext = null; |
| | | 198 | | |
| | 53 | 199 | | await receiveContext.AbandonAsync(CancellationToken.None); |
| | | 200 | | } |
| | 54 | 201 | | } |
| | 0 | 202 | | catch (Exception e) |
| | | 203 | | { |
| | 0 | 204 | | if (Fx.IsFatal(e)) |
| | | 205 | | { |
| | 0 | 206 | | throw; |
| | | 207 | | } |
| | | 208 | | |
| | 0 | 209 | | ChannelHandler.HandleError(e); |
| | 0 | 210 | | } |
| | 54 | 211 | | } |
| | | 212 | | |
| | | 213 | | internal async ValueTask AbortRequestContextAsync() |
| | | 214 | | { |
| | 53 | 215 | | if (OperationContext.RequestContext != null) |
| | | 216 | | { |
| | 0 | 217 | | await AbortRequestContextAsync(OperationContext.RequestContext); |
| | | 218 | | } |
| | 53 | 219 | | if ((RequestContext != null) && (RequestContext != OperationContext.RequestContext)) |
| | | 220 | | { |
| | 53 | 221 | | await AbortRequestContextAsync(RequestContext); |
| | | 222 | | } |
| | | 223 | | |
| | 53 | 224 | | TraceCallDurationInDispatcherIfNecessary(false); |
| | 53 | 225 | | } |
| | | 226 | | |
| | | 227 | | private void TraceCallDurationInDispatcherIfNecessary(bool requestContextWasClosedSuccessfully) |
| | | 228 | | { |
| | | 229 | | // only need to trace once (either for the failure or success case) |
| | | 230 | | //if (TD.DispatchFailedIsEnabled()) |
| | | 231 | | //{ |
| | | 232 | | // if (requestContextWasClosedSuccessfully) |
| | | 233 | | // { |
| | | 234 | | // TD.DispatchSuccessful(this.EventTraceActivity, this.Operation.Name); |
| | | 235 | | // } |
| | | 236 | | // else |
| | | 237 | | // { |
| | | 238 | | // TD.DispatchFailed(this.EventTraceActivity, this.Operation.Name); |
| | | 239 | | // } |
| | | 240 | | //} |
| | 2538 | 241 | | } |
| | | 242 | | |
| | | 243 | | internal async Task CloseRequestContextAsync() |
| | | 244 | | { |
| | 2485 | 245 | | if (OperationContext.RequestContext != null) |
| | | 246 | | { |
| | 728 | 247 | | await DisposeRequestContextAsync(OperationContext.RequestContext); |
| | | 248 | | } |
| | 2485 | 249 | | if ((RequestContext != null) && (RequestContext != OperationContext.RequestContext)) |
| | | 250 | | { |
| | 1757 | 251 | | await DisposeRequestContextAsync(RequestContext); |
| | | 252 | | } |
| | 2485 | 253 | | TraceCallDurationInDispatcherIfNecessary(true); |
| | 2485 | 254 | | } |
| | | 255 | | |
| | | 256 | | private async ValueTask DisposeRequestContextAsync(RequestContext context) |
| | | 257 | | { |
| | | 258 | | try |
| | | 259 | | { |
| | 2485 | 260 | | await context.CloseAsync(); |
| | | 261 | | |
| | 2485 | 262 | | /* ReceiveContextRPCFacet */ ReceiveContext receiveContext = ReceiveContext; |
| | 2485 | 263 | | if (receiveContext != null) |
| | | 264 | | { |
| | 1650 | 265 | | ReceiveContext = null; |
| | 1650 | 266 | | await receiveContext.CompleteAsync(CancellationToken.None); |
| | | 267 | | } |
| | 2484 | 268 | | } |
| | 1 | 269 | | catch (Exception e) |
| | | 270 | | { |
| | 1 | 271 | | if (Fx.IsFatal(e)) |
| | | 272 | | { |
| | 0 | 273 | | throw; |
| | | 274 | | } |
| | | 275 | | |
| | 1 | 276 | | await AbortRequestContextAsync(context); |
| | 1 | 277 | | ChannelHandler.HandleError(e); |
| | 1 | 278 | | } |
| | 2485 | 279 | | } |
| | | 280 | | |
| | | 281 | | internal void AbortChannel() |
| | | 282 | | { |
| | 53 | 283 | | if ((Channel != null) && Channel.HasSession) |
| | | 284 | | { |
| | | 285 | | try |
| | | 286 | | { |
| | 0 | 287 | | Channel.Abort(); |
| | 0 | 288 | | } |
| | 0 | 289 | | catch (Exception e) |
| | | 290 | | { |
| | 0 | 291 | | if (Fx.IsFatal(e)) |
| | | 292 | | { |
| | 0 | 293 | | throw; |
| | | 294 | | } |
| | | 295 | | |
| | 0 | 296 | | ChannelHandler.HandleError(e); |
| | 0 | 297 | | } |
| | | 298 | | } |
| | 53 | 299 | | } |
| | | 300 | | |
| | | 301 | | internal async Task CloseChannelAsync() |
| | | 302 | | { |
| | 5 | 303 | | if ((Channel != null) && Channel.HasSession) |
| | | 304 | | { |
| | | 305 | | try |
| | | 306 | | { |
| | 0 | 307 | | var helper = new TimeoutHelper(ChannelHandler.CloseAfterFaultTimeout); |
| | 0 | 308 | | await Channel.CloseAsync(helper.GetCancellationToken()); |
| | 0 | 309 | | } |
| | 0 | 310 | | catch (Exception e) |
| | | 311 | | { |
| | 0 | 312 | | if (Fx.IsFatal(e)) |
| | | 313 | | { |
| | 0 | 314 | | throw; |
| | | 315 | | } |
| | | 316 | | |
| | 0 | 317 | | ChannelHandler.HandleError(e); |
| | 0 | 318 | | } |
| | | 319 | | } |
| | 5 | 320 | | } |
| | | 321 | | |
| | | 322 | | internal void AbortInstanceContext() |
| | | 323 | | { |
| | 58 | 324 | | if (InstanceContext != null && !_isInstanceContextSingleton) |
| | | 325 | | { |
| | | 326 | | try |
| | | 327 | | { |
| | 58 | 328 | | InstanceContext.Abort(); |
| | 58 | 329 | | } |
| | 0 | 330 | | catch (Exception e) |
| | | 331 | | { |
| | 0 | 332 | | if (Fx.IsFatal(e)) |
| | | 333 | | { |
| | 0 | 334 | | throw; |
| | | 335 | | } |
| | | 336 | | |
| | 0 | 337 | | ChannelHandler.HandleError(e); |
| | 0 | 338 | | } |
| | | 339 | | } |
| | 58 | 340 | | } |
| | | 341 | | |
| | | 342 | | internal void EnsureReceive() |
| | | 343 | | { |
| | | 344 | | //using (ServiceModelActivity.BoundOperation(this.Activity)) |
| | | 345 | | //{ |
| | 2536 | 346 | | ChannelHandler.EnsureReceive(); |
| | | 347 | | //} |
| | 2536 | 348 | | } |
| | | 349 | | |
| | | 350 | | private bool ProcessError(Exception e) |
| | | 351 | | { |
| | 163 | 352 | | MessageRpcErrorHandler handler = ErrorProcessor; |
| | | 353 | | try |
| | | 354 | | { |
| | 163 | 355 | | Type exceptionType = e.GetType(); |
| | | 356 | | |
| | 163 | 357 | | if (exceptionType.IsAssignableFrom(typeof(FaultException))) |
| | | 358 | | { |
| | 93 | 359 | | DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); |
| | | 360 | | } |
| | | 361 | | else |
| | | 362 | | { |
| | 70 | 363 | | DiagnosticUtility.TraceHandledException(e, TraceEventType.Error); |
| | | 364 | | } |
| | | 365 | | |
| | | 366 | | //if (TraceUtility.MessageFlowTracingOnly) |
| | | 367 | | //{ |
| | | 368 | | // TraceUtility.SetActivityId(this.Request.Properties); |
| | | 369 | | // if (Guid.Empty == DiagnosticTraceBase.ActivityId) |
| | | 370 | | // { |
| | | 371 | | // Guid receivedActivityId = TraceUtility.ExtractActivityId(this.Request); |
| | | 372 | | // if (Guid.Empty != receivedActivityId) |
| | | 373 | | // { |
| | | 374 | | // DiagnosticTraceBase.ActivityId = receivedActivityId; |
| | | 375 | | // } |
| | | 376 | | // } |
| | | 377 | | //} |
| | | 378 | | |
| | | 379 | | |
| | 163 | 380 | | Error = e; |
| | | 381 | | |
| | 163 | 382 | | if (ErrorProcessor != null) |
| | | 383 | | { |
| | 163 | 384 | | ErrorProcessor(this); |
| | | 385 | | } |
| | | 386 | | |
| | 163 | 387 | | return (Error == null); |
| | | 388 | | } |
| | 0 | 389 | | catch (Exception e2) |
| | | 390 | | { |
| | 0 | 391 | | if (Fx.IsFatal(e2)) |
| | | 392 | | { |
| | 0 | 393 | | throw; |
| | | 394 | | } |
| | | 395 | | |
| | 0 | 396 | | return ((handler != ErrorProcessor) && ProcessError(e2)); |
| | | 397 | | } |
| | 163 | 398 | | } |
| | | 399 | | |
| | | 400 | | internal void DisposeParameters(bool excludeInput) |
| | | 401 | | { |
| | 2538 | 402 | | if (Operation.DisposeParameters) |
| | | 403 | | { |
| | 365 | 404 | | DisposeParametersCore(excludeInput); |
| | | 405 | | } |
| | 2538 | 406 | | } |
| | | 407 | | |
| | | 408 | | internal void DisposeParametersCore(bool excludeInput) |
| | | 409 | | { |
| | 365 | 410 | | if (!ParametersDisposed) |
| | | 411 | | { |
| | 365 | 412 | | if (!excludeInput) |
| | | 413 | | { |
| | 365 | 414 | | DisposeParameterList(InputParameters); |
| | | 415 | | } |
| | | 416 | | |
| | 365 | 417 | | DisposeParameterList(OutputParameters); |
| | | 418 | | |
| | 365 | 419 | | if (ReturnParameter is IDisposable disposableParameter) |
| | | 420 | | { |
| | | 421 | | try |
| | | 422 | | { |
| | 26 | 423 | | disposableParameter.Dispose(); |
| | 26 | 424 | | } |
| | 0 | 425 | | catch (Exception e) |
| | | 426 | | { |
| | 0 | 427 | | if (Fx.IsFatal(e)) |
| | | 428 | | { |
| | 0 | 429 | | throw; |
| | | 430 | | } |
| | | 431 | | |
| | 0 | 432 | | ChannelHandler.HandleError(e); |
| | 0 | 433 | | } |
| | | 434 | | } |
| | | 435 | | |
| | 365 | 436 | | ParametersDisposed = true; |
| | | 437 | | } |
| | 365 | 438 | | } |
| | | 439 | | |
| | | 440 | | private void DisposeParameterList(object[] parameters) |
| | | 441 | | { |
| | 730 | 442 | | if (parameters != null) |
| | | 443 | | { |
| | 2130 | 444 | | foreach (object obj in parameters) |
| | | 445 | | { |
| | 377 | 446 | | if (obj is IDisposable disposableParameter) |
| | | 447 | | { |
| | | 448 | | try |
| | | 449 | | { |
| | 43 | 450 | | disposableParameter.Dispose(); |
| | 43 | 451 | | } |
| | 0 | 452 | | catch (Exception e) |
| | | 453 | | { |
| | 0 | 454 | | if (Fx.IsFatal(e)) |
| | | 455 | | { |
| | 0 | 456 | | throw; |
| | | 457 | | } |
| | | 458 | | |
| | 0 | 459 | | ChannelHandler.HandleError(e); |
| | 0 | 460 | | } |
| | | 461 | | } |
| | | 462 | | } |
| | | 463 | | } |
| | 730 | 464 | | } |
| | | 465 | | |
| | | 466 | | internal async Task<MessageRpc> ProcessAsync(bool isOperationContextSet) |
| | | 467 | | { |
| | | 468 | | MessageRpc result = this; |
| | | 469 | | //using (ServiceModelActivity.BoundOperation(this.Activity)) |
| | | 470 | | //{ |
| | | 471 | | // bool completed = true; |
| | | 472 | | |
| | | 473 | | OperationContext originalContext; |
| | 2538 | 474 | | if (!isOperationContextSet) |
| | | 475 | | { |
| | 2538 | 476 | | originalContext = OperationContext.Current; |
| | | 477 | | } |
| | | 478 | | else |
| | | 479 | | { |
| | 0 | 480 | | originalContext = null; |
| | | 481 | | } |
| | 2538 | 482 | | IncrementBusyCount(); |
| | | 483 | | |
| | | 484 | | try |
| | | 485 | | { |
| | 2538 | 486 | | if (!isOperationContextSet) |
| | | 487 | | { |
| | 2538 | 488 | | OperationContext.Current = OperationContext; |
| | | 489 | | } |
| | | 490 | | |
| | 2538 | 491 | | await AsyncProcessor(this); |
| | | 492 | | |
| | 2375 | 493 | | OperationContext.SetClientReply(null, false); |
| | 2375 | 494 | | } |
| | 163 | 495 | | catch (Exception e) |
| | | 496 | | { |
| | 163 | 497 | | if (Fx.IsFatal(e)) |
| | | 498 | | { |
| | 0 | 499 | | throw; |
| | | 500 | | } |
| | 163 | 501 | | if (!ProcessError(e) && FaultInfo.Fault == null) |
| | | 502 | | { |
| | 0 | 503 | | await AbortAsync(); |
| | | 504 | | } |
| | | 505 | | } |
| | | 506 | | finally |
| | | 507 | | { |
| | | 508 | | try |
| | | 509 | | { |
| | 2538 | 510 | | DecrementBusyCount(); |
| | | 511 | | |
| | 2538 | 512 | | if (!isOperationContextSet) |
| | | 513 | | { |
| | 2538 | 514 | | OperationContext.Current = originalContext; |
| | | 515 | | } |
| | | 516 | | |
| | 2538 | 517 | | OperationContext.ClearClientReplyNoThrow(); |
| | 2538 | 518 | | } |
| | 0 | 519 | | catch (Exception e) |
| | | 520 | | { |
| | 0 | 521 | | if (Fx.IsFatal(e)) |
| | | 522 | | { |
| | | 523 | | #pragma warning disable CA2219 // Do not raise exceptions in finally clauses - Fx.IsFatal filters out non-process ending |
| | 0 | 524 | | throw; |
| | | 525 | | #pragma warning restore CA2219 // Do not raise exceptions in finally clauses |
| | | 526 | | } |
| | 0 | 527 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperFatal(e.Message, e); |
| | | 528 | | } |
| | | 529 | | } |
| | | 530 | | |
| | 2538 | 531 | | return this; |
| | | 532 | | //} |
| | 2538 | 533 | | } |
| | | 534 | | |
| | | 535 | | // UnPause is called on the original MessageRpc to continue work on the current thread, and the copy is ignored. |
| | | 536 | | // Since the copy is ignored, Decrement the BusyCount |
| | | 537 | | internal void UnPause() |
| | | 538 | | { |
| | 0 | 539 | | IsPaused = false; |
| | 0 | 540 | | DecrementBusyCount(); |
| | 0 | 541 | | } |
| | | 542 | | |
| | | 543 | | internal bool UnlockInvokeContinueGate(out IAsyncResult result) |
| | | 544 | | { |
| | 0 | 545 | | return _invokeContinueGate.Unlock(out result); |
| | | 546 | | } |
| | | 547 | | |
| | | 548 | | internal void PrepareInvokeContinueGate() |
| | | 549 | | { |
| | 0 | 550 | | _invokeContinueGate = new SignalGate<IAsyncResult>(); |
| | 0 | 551 | | } |
| | | 552 | | |
| | | 553 | | private void IncrementBusyCount() |
| | | 554 | | { |
| | | 555 | | // TODO: Do we want a way to keep track of bust count? I believe this originally drove PerformanceCounters s |
| | | 556 | | // Only increment the counter on the service side. |
| | | 557 | | //if (Host != null) |
| | | 558 | | //{ |
| | | 559 | | //Host.IncrementBusyCount(); |
| | | 560 | | //if (AspNetEnvironment.Current.TraceIncrementBusyCountIsEnabled()) |
| | | 561 | | //{ |
| | | 562 | | // AspNetEnvironment.Current.TraceIncrementBusyCount(SR.Format(SR.ServiceBusyCountTrace, this.Operation.A |
| | | 563 | | //} |
| | | 564 | | //} |
| | 2538 | 565 | | } |
| | | 566 | | |
| | | 567 | | private void DecrementBusyCount() |
| | | 568 | | { |
| | | 569 | | // See comment on IncrementBusyCount |
| | | 570 | | //if (Host != null) |
| | | 571 | | //{ |
| | | 572 | | // Host.DecrementBusyCount(); |
| | | 573 | | //if (AspNetEnvironment.Current.TraceDecrementBusyCountIsEnabled()) |
| | | 574 | | //{ |
| | | 575 | | // AspNetEnvironment.Current.TraceDecrementBusyCount(SR.Format(SR.ServiceBusyCountTrace, this.Operation.A |
| | | 576 | | //} |
| | | 577 | | //} |
| | 2538 | 578 | | } |
| | | 579 | | } |
| | | 580 | | } |