MessageEncodingBindingElement.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Channels
  5. {
  6. using System.Collections.Generic;
  7. using System.ServiceModel.Description;
  8. using System.Runtime.Serialization;
  9. using System.ServiceModel;
  10. using System.ServiceModel.Diagnostics;
  11. using System.Xml;
  12. public abstract class MessageEncodingBindingElement : BindingElement
  13. {
  14. protected MessageEncodingBindingElement()
  15. {
  16. }
  17. protected MessageEncodingBindingElement(MessageEncodingBindingElement elementToBeCloned)
  18. : base(elementToBeCloned)
  19. {
  20. }
  21. public abstract MessageVersion MessageVersion { get; set; }
  22. internal virtual bool IsWsdlExportable
  23. {
  24. get { return true; }
  25. }
  26. internal IChannelFactory<TChannel> InternalBuildChannelFactory<TChannel>(BindingContext context)
  27. {
  28. if (context == null)
  29. {
  30. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("context"));
  31. }
  32. #pragma warning suppress 56506 // [....], BindingContext.BindingParameters never be null
  33. context.BindingParameters.Add(this);
  34. return context.BuildInnerChannelFactory<TChannel>();
  35. }
  36. internal bool InternalCanBuildChannelFactory<TChannel>(BindingContext context)
  37. {
  38. if (context == null)
  39. {
  40. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("context"));
  41. }
  42. #pragma warning suppress 56506 // [....], BindingContext.BindingParameters never be null
  43. context.BindingParameters.Add(this);
  44. return context.CanBuildInnerChannelFactory<TChannel>();
  45. }
  46. internal IChannelListener<TChannel> InternalBuildChannelListener<TChannel>(BindingContext context)
  47. where TChannel : class, IChannel
  48. {
  49. if (context == null)
  50. {
  51. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("context"));
  52. }
  53. #pragma warning suppress 56506 // [....], BindingContext.BindingParameters never be null
  54. context.BindingParameters.Add(this);
  55. return context.BuildInnerChannelListener<TChannel>();
  56. }
  57. internal bool InternalCanBuildChannelListener<TChannel>(BindingContext context)
  58. where TChannel : class, IChannel
  59. {
  60. if (context == null)
  61. {
  62. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("context"));
  63. }
  64. #pragma warning suppress 56506 // [....], BindingContext.BindingParameters never be null
  65. context.BindingParameters.Add(this);
  66. return context.CanBuildInnerChannelListener<TChannel>();
  67. }
  68. public abstract MessageEncoderFactory CreateMessageEncoderFactory();
  69. public override T GetProperty<T>(BindingContext context)
  70. {
  71. if (context == null)
  72. {
  73. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
  74. }
  75. if (typeof(T) == typeof(MessageVersion))
  76. {
  77. return (T)(object)this.MessageVersion;
  78. }
  79. else
  80. {
  81. return context.GetInnerProperty<T>();
  82. }
  83. }
  84. internal virtual bool CheckEncodingVersion(EnvelopeVersion version)
  85. {
  86. return false;
  87. }
  88. internal override bool IsMatch(BindingElement b)
  89. {
  90. if (b == null)
  91. return false;
  92. MessageEncodingBindingElement encoding = b as MessageEncodingBindingElement;
  93. if (encoding == null)
  94. return false;
  95. return true;
  96. }
  97. }
  98. }