MessageDescription.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Description
  5. {
  6. using System.Collections.Generic;
  7. using System.ServiceModel.Channels;
  8. using System.ServiceModel;
  9. using System.Xml;
  10. using System.Runtime.Serialization;
  11. using System.Diagnostics;
  12. using System.Net.Security;
  13. using System.ServiceModel.Security;
  14. using System.ComponentModel;
  15. [DebuggerDisplay("Action={action}, Direction={direction}, MessageType={messageType}")]
  16. public class MessageDescription
  17. {
  18. static Type typeOfUntypedMessage;
  19. string action;
  20. MessageDirection direction;
  21. MessageDescriptionItems items;
  22. XmlName messageName;
  23. Type messageType;
  24. XmlQualifiedName xsdType;
  25. ProtectionLevel protectionLevel;
  26. bool hasProtectionLevel;
  27. public MessageDescription(string action, MessageDirection direction) : this(action, direction, null) { }
  28. internal MessageDescription(string action, MessageDirection direction, MessageDescriptionItems items)
  29. {
  30. if (!MessageDirectionHelper.IsDefined(direction))
  31. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("direction"));
  32. this.action = action;
  33. this.direction = direction;
  34. this.items = items;
  35. }
  36. internal MessageDescription(MessageDescription other)
  37. {
  38. this.action = other.action;
  39. this.direction = other.direction;
  40. this.Items.Body = other.Items.Body.Clone();
  41. foreach (MessageHeaderDescription mhd in other.Items.Headers)
  42. {
  43. this.Items.Headers.Add(mhd.Clone() as MessageHeaderDescription);
  44. }
  45. foreach (MessagePropertyDescription mpd in other.Items.Properties)
  46. {
  47. this.Items.Properties.Add(mpd.Clone() as MessagePropertyDescription);
  48. }
  49. this.MessageName = other.MessageName;
  50. this.MessageType = other.MessageType;
  51. this.XsdTypeName = other.XsdTypeName;
  52. this.hasProtectionLevel = other.hasProtectionLevel;
  53. this.ProtectionLevel = other.ProtectionLevel;
  54. }
  55. internal MessageDescription Clone()
  56. {
  57. return new MessageDescription(this);
  58. }
  59. public string Action
  60. {
  61. get { return action; }
  62. internal set { action = value; }
  63. }
  64. public MessageBodyDescription Body
  65. {
  66. get { return Items.Body; }
  67. }
  68. public MessageDirection Direction
  69. {
  70. get { return direction; }
  71. }
  72. public MessageHeaderDescriptionCollection Headers
  73. {
  74. get { return Items.Headers; }
  75. }
  76. public MessagePropertyDescriptionCollection Properties
  77. {
  78. get { return Items.Properties; }
  79. }
  80. internal MessageDescriptionItems Items
  81. {
  82. get
  83. {
  84. if (items == null)
  85. items = new MessageDescriptionItems();
  86. return items;
  87. }
  88. }
  89. public ProtectionLevel ProtectionLevel
  90. {
  91. get { return this.protectionLevel; }
  92. set
  93. {
  94. if (!ProtectionLevelHelper.IsDefined(value))
  95. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
  96. this.protectionLevel = value;
  97. this.hasProtectionLevel = true;
  98. }
  99. }
  100. public bool ShouldSerializeProtectionLevel()
  101. {
  102. return this.HasProtectionLevel;
  103. }
  104. public bool HasProtectionLevel
  105. {
  106. get { return this.hasProtectionLevel; }
  107. }
  108. internal static Type TypeOfUntypedMessage
  109. {
  110. get
  111. {
  112. if (typeOfUntypedMessage == null)
  113. {
  114. typeOfUntypedMessage = typeof(Message);
  115. }
  116. return typeOfUntypedMessage;
  117. }
  118. }
  119. internal XmlName MessageName
  120. {
  121. get { return messageName; }
  122. set { messageName = value; }
  123. }
  124. // Not serializable on purpose, metadata import/export cannot
  125. // produce it, only available when binding to runtime
  126. [DefaultValue(null)]
  127. public Type MessageType
  128. {
  129. get { return messageType; }
  130. set { messageType = value; }
  131. }
  132. internal bool IsTypedMessage
  133. {
  134. get
  135. {
  136. return messageType != null;
  137. }
  138. }
  139. internal bool IsUntypedMessage
  140. {
  141. get
  142. {
  143. return (Body.ReturnValue != null && Body.Parts.Count == 0 && Body.ReturnValue.Type == TypeOfUntypedMessage) ||
  144. (Body.ReturnValue == null && Body.Parts.Count == 1 && Body.Parts[0].Type == TypeOfUntypedMessage);
  145. }
  146. }
  147. internal bool IsVoid
  148. {
  149. get
  150. {
  151. return !IsTypedMessage && Body.Parts.Count == 0 && (Body.ReturnValue == null || Body.ReturnValue.Type == typeof(void));
  152. }
  153. }
  154. internal XmlQualifiedName XsdTypeName
  155. {
  156. get { return xsdType; }
  157. set { xsdType = value; }
  158. }
  159. internal void ResetProtectionLevel()
  160. {
  161. this.protectionLevel = ProtectionLevel.None;
  162. this.hasProtectionLevel = false;
  163. }
  164. }
  165. internal class MessageDescriptionItems
  166. {
  167. MessageHeaderDescriptionCollection headers;
  168. MessageBodyDescription body;
  169. MessagePropertyDescriptionCollection properties;
  170. internal MessageBodyDescription Body
  171. {
  172. get
  173. {
  174. if (body == null)
  175. body = new MessageBodyDescription();
  176. return body;
  177. }
  178. set
  179. {
  180. this.body = value;
  181. }
  182. }
  183. internal MessageHeaderDescriptionCollection Headers
  184. {
  185. get
  186. {
  187. if (headers == null)
  188. headers = new MessageHeaderDescriptionCollection();
  189. return headers;
  190. }
  191. }
  192. internal MessagePropertyDescriptionCollection Properties
  193. {
  194. get
  195. {
  196. if (properties == null)
  197. properties = new MessagePropertyDescriptionCollection();
  198. return properties;
  199. }
  200. }
  201. }
  202. }