FaultContractAttribute.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel
  5. {
  6. using System.Reflection;
  7. using System.ServiceModel.Security;
  8. using System.Net.Security;
  9. using System.ServiceModel.Description;
  10. [AttributeUsage(ServiceModelAttributeTargets.OperationContract, AllowMultiple = true, Inherited = false)]
  11. public sealed class FaultContractAttribute : Attribute
  12. {
  13. string action;
  14. string name;
  15. string ns;
  16. Type type;
  17. ProtectionLevel protectionLevel = ProtectionLevel.None;
  18. bool hasProtectionLevel = false;
  19. public FaultContractAttribute(Type detailType)
  20. {
  21. if (detailType == null)
  22. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("detailType"));
  23. this.type = detailType;
  24. }
  25. public Type DetailType
  26. {
  27. get { return this.type; }
  28. }
  29. public string Action
  30. {
  31. get { return this.action; }
  32. set
  33. {
  34. if (value == null)
  35. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
  36. this.action = value;
  37. }
  38. }
  39. public string Name
  40. {
  41. get { return this.name; }
  42. set
  43. {
  44. if (value == null)
  45. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
  46. if (value == string.Empty)
  47. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value",
  48. SR.GetString(SR.SFxNameCannotBeEmpty)));
  49. this.name = value;
  50. }
  51. }
  52. public string Namespace
  53. {
  54. get { return this.ns; }
  55. set
  56. {
  57. if (!string.IsNullOrEmpty(value))
  58. NamingHelper.CheckUriProperty(value, "Namespace");
  59. this.ns = value;
  60. }
  61. }
  62. internal const string ProtectionLevelPropertyName = "ProtectionLevel";
  63. public ProtectionLevel ProtectionLevel
  64. {
  65. get
  66. {
  67. return this.protectionLevel;
  68. }
  69. set
  70. {
  71. if (!ProtectionLevelHelper.IsDefined(value))
  72. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
  73. this.protectionLevel = value;
  74. this.hasProtectionLevel = true;
  75. }
  76. }
  77. public bool HasProtectionLevel
  78. {
  79. get { return this.hasProtectionLevel; }
  80. }
  81. }
  82. }