ServiceContractAttribute.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel
  5. {
  6. using System;
  7. using System.ServiceModel.Description;
  8. using System.Transactions;
  9. using System.ServiceModel.Channels;
  10. using System.Runtime.CompilerServices;
  11. using System.Net.Security;
  12. using System.ServiceModel.Security;
  13. [AttributeUsage(ServiceModelAttributeTargets.ServiceContract, Inherited = false, AllowMultiple = false)]
  14. public sealed class ServiceContractAttribute : Attribute
  15. {
  16. Type callbackContract = null;
  17. string configurationName;
  18. string name;
  19. string ns;
  20. SessionMode sessionMode;
  21. ProtectionLevel protectionLevel = ProtectionLevel.None;
  22. bool hasProtectionLevel = false;
  23. public string ConfigurationName
  24. {
  25. get { return this.configurationName; }
  26. set
  27. {
  28. if (value == null)
  29. {
  30. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
  31. }
  32. if (value == string.Empty)
  33. {
  34. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value",
  35. SR.GetString(SR.SFxConfigurationNameCannotBeEmpty)));
  36. }
  37. this.configurationName = value;
  38. }
  39. }
  40. public string Name
  41. {
  42. get { return name; }
  43. set
  44. {
  45. if (value == null)
  46. {
  47. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
  48. }
  49. if (value == string.Empty)
  50. {
  51. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value",
  52. SR.GetString(SR.SFxNameCannotBeEmpty)));
  53. }
  54. name = value;
  55. }
  56. }
  57. public string Namespace
  58. {
  59. get { return ns; }
  60. set
  61. {
  62. if (!string.IsNullOrEmpty(value))
  63. NamingHelper.CheckUriProperty(value, "Namespace");
  64. ns = value;
  65. }
  66. }
  67. public ProtectionLevel ProtectionLevel
  68. {
  69. get
  70. {
  71. return this.protectionLevel;
  72. }
  73. set
  74. {
  75. if (!ProtectionLevelHelper.IsDefined(value))
  76. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
  77. this.protectionLevel = value;
  78. this.hasProtectionLevel = true;
  79. }
  80. }
  81. public bool HasProtectionLevel
  82. {
  83. get { return this.hasProtectionLevel; }
  84. }
  85. public SessionMode SessionMode
  86. {
  87. get { return this.sessionMode; }
  88. set
  89. {
  90. if (!SessionModeHelper.IsDefined(value))
  91. {
  92. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
  93. }
  94. this.sessionMode = value;
  95. }
  96. }
  97. public Type CallbackContract
  98. {
  99. get { return this.callbackContract; }
  100. set { this.callbackContract = value; }
  101. }
  102. }
  103. }