NetTcpContextBindingElement.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System;
  7. using System.Configuration;
  8. using System.Diagnostics.CodeAnalysis;
  9. using System.Net.Security;
  10. using System.Runtime;
  11. using System.Runtime.CompilerServices;
  12. using System.ServiceModel.Channels;
  13. using System.ServiceModel.Security;
  14. [TypeForwardedFrom("System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
  15. public partial class NetTcpContextBindingElement : NetTcpBindingElement
  16. {
  17. const string ContextManagementEnabledName = ContextBindingElementExtensionElement.ContextManagementEnabledName;
  18. const string ContextProtectionLevelName = "contextProtectionLevel";
  19. public NetTcpContextBindingElement()
  20. : base()
  21. {
  22. }
  23. public NetTcpContextBindingElement(string name)
  24. : base(name)
  25. {
  26. }
  27. [ConfigurationProperty(ConfigurationStrings.ClientCallbackAddressName, DefaultValue = null)]
  28. [SuppressMessage(FxCop.Category.Configuration, FxCop.Rule.ConfigurationValidatorAttributeRule,
  29. Justification = "Is of type Uri, we don't have a validator for it")]
  30. public Uri ClientCallbackAddress
  31. {
  32. get { return (Uri)base[ConfigurationStrings.ClientCallbackAddressName]; }
  33. set { base[ConfigurationStrings.ClientCallbackAddressName] = value; }
  34. }
  35. [ConfigurationProperty(ContextManagementEnabledName, DefaultValue = ContextBindingElement.DefaultContextManagementEnabled)]
  36. public bool ContextManagementEnabled
  37. {
  38. get { return (bool)base[ContextManagementEnabledName]; }
  39. set { base[ContextManagementEnabledName] = value; }
  40. }
  41. [ConfigurationProperty(ContextProtectionLevelName, DefaultValue = ContextBindingElement.DefaultProtectionLevel)]
  42. [ServiceModelEnumValidator(typeof(ProtectionLevelHelper))]
  43. public ProtectionLevel ContextProtectionLevel
  44. {
  45. get { return (ProtectionLevel) base[ContextProtectionLevelName]; }
  46. set { base[ContextProtectionLevelName] = value; }
  47. }
  48. protected override Type BindingElementType
  49. {
  50. get { return typeof(NetTcpContextBinding); }
  51. }
  52. protected internal override void InitializeFrom(Binding binding)
  53. {
  54. base.InitializeFrom(binding);
  55. NetTcpContextBinding netTcpContextBinding = (NetTcpContextBinding)binding;
  56. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ClientCallbackAddressName, netTcpContextBinding.ClientCallbackAddress);
  57. SetPropertyValueIfNotDefaultValue(NetTcpContextBindingElement.ContextManagementEnabledName, netTcpContextBinding.ContextManagementEnabled);
  58. SetPropertyValueIfNotDefaultValue(NetTcpContextBindingElement.ContextProtectionLevelName, netTcpContextBinding.ContextProtectionLevel);
  59. }
  60. protected override void OnApplyConfiguration(Binding binding)
  61. {
  62. base.OnApplyConfiguration(binding);
  63. NetTcpContextBinding netTcpContextBinding = (NetTcpContextBinding)binding;
  64. netTcpContextBinding.ClientCallbackAddress = this.ClientCallbackAddress;
  65. netTcpContextBinding.ContextManagementEnabled = this.ContextManagementEnabled;
  66. netTcpContextBinding.ContextProtectionLevel = this.ContextProtectionLevel;
  67. }
  68. }
  69. }