CallbackTimeoutsBehavior.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Description
  5. {
  6. using System.Runtime;
  7. using System.ServiceModel;
  8. using System.ServiceModel.Channels;
  9. using System.ServiceModel.Dispatcher;
  10. class CallbackTimeoutsBehavior : IEndpointBehavior
  11. {
  12. TimeSpan transactionTimeout = TimeSpan.Zero;
  13. public TimeSpan TransactionTimeout
  14. {
  15. get { return this.transactionTimeout; }
  16. set
  17. {
  18. if (value < TimeSpan.Zero)
  19. {
  20. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  21. SR.GetString(SR.SFxTimeoutOutOfRange0)));
  22. }
  23. if (TimeoutHelper.IsTooLarge(value))
  24. {
  25. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  26. SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
  27. }
  28. this.transactionTimeout = value;
  29. }
  30. }
  31. public CallbackTimeoutsBehavior()
  32. {
  33. }
  34. void IEndpointBehavior.Validate(ServiceEndpoint serviceEndpoint)
  35. {
  36. }
  37. void IEndpointBehavior.AddBindingParameters(ServiceEndpoint serviceEndpoint, BindingParameterCollection bindingParameters)
  38. {
  39. }
  40. void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatcher)
  41. {
  42. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
  43. SR.GetString(SR.SFXEndpointBehaviorUsedOnWrongSide, typeof(CallbackTimeoutsBehavior).Name)));
  44. }
  45. void IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime behavior)
  46. {
  47. if (this.transactionTimeout != TimeSpan.Zero)
  48. {
  49. ChannelDispatcher channelDispatcher = behavior.CallbackDispatchRuntime.ChannelDispatcher;
  50. if ((channelDispatcher != null) &&
  51. (channelDispatcher.TransactionTimeout == TimeSpan.Zero) ||
  52. (channelDispatcher.TransactionTimeout > this.transactionTimeout))
  53. {
  54. channelDispatcher.TransactionTimeout = this.transactionTimeout;
  55. }
  56. }
  57. }
  58. }
  59. }