MessageHeaderException.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //-----------------------------------------------------------------------------
  4. namespace System.ServiceModel
  5. {
  6. using System;
  7. using System.Runtime;
  8. using System.Runtime.Serialization;
  9. using System.ServiceModel.Channels;
  10. [Serializable]
  11. public class MessageHeaderException : ProtocolException
  12. {
  13. [NonSerialized]
  14. string headerName;
  15. [NonSerialized]
  16. string headerNamespace;
  17. [NonSerialized]
  18. bool isDuplicate;
  19. public MessageHeaderException(string message)
  20. : this(message, null, null)
  21. {
  22. }
  23. public MessageHeaderException(string message, bool isDuplicate)
  24. : this(message, null, null)
  25. {
  26. }
  27. public MessageHeaderException(string message, Exception innerException)
  28. : this(message, null, null, innerException)
  29. {
  30. }
  31. public MessageHeaderException(string message, string headerName, string ns)
  32. : this(message, headerName, ns, null)
  33. {
  34. }
  35. public MessageHeaderException(string message, string headerName, string ns, bool isDuplicate)
  36. : this(message, headerName, ns, isDuplicate, null)
  37. {
  38. }
  39. public MessageHeaderException(string message, string headerName, string ns, Exception innerException)
  40. : this(message, headerName, ns, false, innerException)
  41. {
  42. }
  43. public MessageHeaderException(string message, string headerName, string ns, bool isDuplicate, Exception innerException)
  44. : base(message, innerException)
  45. {
  46. this.headerName = headerName;
  47. this.headerNamespace = ns;
  48. this.isDuplicate = isDuplicate;
  49. }
  50. public string HeaderName { get { return this.headerName; } }
  51. public string HeaderNamespace { get { return this.headerNamespace; } }
  52. // IsDuplicate==true means there was more than one; IsDuplicate==false means there were zero
  53. public bool IsDuplicate { get { return this.isDuplicate; } }
  54. internal Message ProvideFault(MessageVersion messageVersion)
  55. {
  56. Fx.Assert(messageVersion.Addressing == AddressingVersion.WSAddressing10, "");
  57. WSAddressing10ProblemHeaderQNameFault phf = new WSAddressing10ProblemHeaderQNameFault(this);
  58. Message message = System.ServiceModel.Channels.Message.CreateMessage(messageVersion, phf, AddressingVersion.WSAddressing10.FaultAction);
  59. phf.AddHeaders(message.Headers);
  60. return message;
  61. }
  62. // for serialization
  63. public MessageHeaderException() { }
  64. protected MessageHeaderException(SerializationInfo info, StreamingContext context) : base(info, context) { }
  65. }
  66. }