ClientOperation.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //-----------------------------------------------------------------------------
  4. namespace System.ServiceModel.Dispatcher
  5. {
  6. using System;
  7. using System.Reflection;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Diagnostics.CodeAnalysis;
  11. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Compat", Justification = "Compat is an accepted abbreviation")]
  12. [EditorBrowsable(EditorBrowsableState.Never)]
  13. public class ClientOperationCompatBase
  14. {
  15. internal ClientOperationCompatBase() { }
  16. [EditorBrowsable(EditorBrowsableState.Never)]
  17. [Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
  18. public IList<IParameterInspector> ParameterInspectors
  19. {
  20. get
  21. {
  22. return this.parameterInspectors;
  23. }
  24. }
  25. internal SynchronizedCollection<IParameterInspector> parameterInspectors;
  26. }
  27. public sealed class ClientOperation : ClientOperationCompatBase
  28. {
  29. string action;
  30. SynchronizedCollection<FaultContractInfo> faultContractInfos;
  31. bool serializeRequest;
  32. bool deserializeReply;
  33. IClientMessageFormatter formatter;
  34. IClientFaultFormatter faultFormatter;
  35. bool isInitiating = true;
  36. bool isOneWay;
  37. bool isTerminating;
  38. bool isSessionOpenNotificationEnabled;
  39. string name;
  40. ClientRuntime parent;
  41. string replyAction;
  42. MethodInfo beginMethod;
  43. MethodInfo endMethod;
  44. MethodInfo syncMethod;
  45. MethodInfo taskMethod;
  46. Type taskTResult;
  47. bool isFaultFormatterSetExplicit = false;
  48. public ClientOperation(ClientRuntime parent, string name, string action)
  49. : this(parent, name, action, null)
  50. {
  51. }
  52. public ClientOperation(ClientRuntime parent, string name, string action, string replyAction)
  53. {
  54. if (parent == null)
  55. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("parent");
  56. if (name == null)
  57. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("name");
  58. this.parent = parent;
  59. this.name = name;
  60. this.action = action;
  61. this.replyAction = replyAction;
  62. this.faultContractInfos = parent.NewBehaviorCollection<FaultContractInfo>();
  63. this.parameterInspectors = parent.NewBehaviorCollection<IParameterInspector>();
  64. }
  65. public string Action
  66. {
  67. get { return this.action; }
  68. }
  69. public SynchronizedCollection<FaultContractInfo> FaultContractInfos
  70. {
  71. get { return this.faultContractInfos; }
  72. }
  73. public MethodInfo BeginMethod
  74. {
  75. get { return this.beginMethod; }
  76. set
  77. {
  78. lock (this.parent.ThisLock)
  79. {
  80. this.parent.InvalidateRuntime();
  81. this.beginMethod = value;
  82. }
  83. }
  84. }
  85. public MethodInfo EndMethod
  86. {
  87. get { return this.endMethod; }
  88. set
  89. {
  90. lock (this.parent.ThisLock)
  91. {
  92. this.parent.InvalidateRuntime();
  93. this.endMethod = value;
  94. }
  95. }
  96. }
  97. public MethodInfo SyncMethod
  98. {
  99. get { return this.syncMethod; }
  100. set
  101. {
  102. lock (this.parent.ThisLock)
  103. {
  104. this.parent.InvalidateRuntime();
  105. this.syncMethod = value;
  106. }
  107. }
  108. }
  109. public IClientMessageFormatter Formatter
  110. {
  111. get { return this.formatter; }
  112. set
  113. {
  114. lock (this.parent.ThisLock)
  115. {
  116. this.parent.InvalidateRuntime();
  117. this.formatter = value;
  118. }
  119. }
  120. }
  121. internal IClientFaultFormatter FaultFormatter
  122. {
  123. get
  124. {
  125. if (this.faultFormatter == null)
  126. {
  127. this.faultFormatter = new DataContractSerializerFaultFormatter(this.faultContractInfos);
  128. }
  129. return this.faultFormatter;
  130. }
  131. set
  132. {
  133. lock (this.parent.ThisLock)
  134. {
  135. this.parent.InvalidateRuntime();
  136. this.faultFormatter = value;
  137. this.isFaultFormatterSetExplicit = true;
  138. }
  139. }
  140. }
  141. internal bool IsFaultFormatterSetExplicit
  142. {
  143. get
  144. {
  145. return this.isFaultFormatterSetExplicit;
  146. }
  147. }
  148. internal IClientMessageFormatter InternalFormatter
  149. {
  150. get { return this.formatter; }
  151. set { this.formatter = value; }
  152. }
  153. public bool IsInitiating
  154. {
  155. get { return this.isInitiating; }
  156. set
  157. {
  158. lock (this.parent.ThisLock)
  159. {
  160. this.parent.InvalidateRuntime();
  161. this.isInitiating = value;
  162. }
  163. }
  164. }
  165. public bool IsOneWay
  166. {
  167. get { return this.isOneWay; }
  168. set
  169. {
  170. lock (this.parent.ThisLock)
  171. {
  172. this.parent.InvalidateRuntime();
  173. this.isOneWay = value;
  174. }
  175. }
  176. }
  177. public bool IsTerminating
  178. {
  179. get { return this.isTerminating; }
  180. set
  181. {
  182. lock (this.parent.ThisLock)
  183. {
  184. this.parent.InvalidateRuntime();
  185. this.isTerminating = value;
  186. }
  187. }
  188. }
  189. public string Name
  190. {
  191. get { return this.name; }
  192. }
  193. public ICollection<IParameterInspector> ClientParameterInspectors
  194. {
  195. get { return this.ParameterInspectors; }
  196. }
  197. [EditorBrowsable(EditorBrowsableState.Never)]
  198. public new SynchronizedCollection<IParameterInspector> ParameterInspectors
  199. {
  200. get { return this.parameterInspectors; }
  201. }
  202. public ClientRuntime Parent
  203. {
  204. get { return this.parent; }
  205. }
  206. public string ReplyAction
  207. {
  208. get { return this.replyAction; }
  209. }
  210. public bool SerializeRequest
  211. {
  212. get { return this.serializeRequest; }
  213. set
  214. {
  215. lock (this.parent.ThisLock)
  216. {
  217. this.parent.InvalidateRuntime();
  218. this.serializeRequest = value;
  219. }
  220. }
  221. }
  222. public bool DeserializeReply
  223. {
  224. get { return this.deserializeReply; }
  225. set
  226. {
  227. lock (this.parent.ThisLock)
  228. {
  229. this.parent.InvalidateRuntime();
  230. this.deserializeReply = value;
  231. }
  232. }
  233. }
  234. public MethodInfo TaskMethod
  235. {
  236. get { return this.taskMethod; }
  237. set
  238. {
  239. lock (this.parent.ThisLock)
  240. {
  241. this.parent.InvalidateRuntime();
  242. this.taskMethod = value;
  243. }
  244. }
  245. }
  246. public Type TaskTResult
  247. {
  248. get { return this.taskTResult; }
  249. set
  250. {
  251. lock (this.parent.ThisLock)
  252. {
  253. this.parent.InvalidateRuntime();
  254. this.taskTResult = value;
  255. }
  256. }
  257. }
  258. internal bool IsSessionOpenNotificationEnabled
  259. {
  260. get { return this.isSessionOpenNotificationEnabled; }
  261. set
  262. {
  263. lock (this.parent.ThisLock)
  264. {
  265. this.parent.InvalidateRuntime();
  266. this.isSessionOpenNotificationEnabled = value;
  267. }
  268. }
  269. }
  270. }
  271. }