DispatchOperation.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. //
  2. // DispatchOperation.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2005-2010 Novell, Inc. http://www.novell.com
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Reflection;
  31. using System.ServiceModel;
  32. using System.ServiceModel.Channels;
  33. using System.ServiceModel.Description;
  34. using System.Text;
  35. namespace System.ServiceModel.Dispatcher
  36. {
  37. public sealed class DispatchOperation
  38. {
  39. internal class DispatchOperationCollection :
  40. SynchronizedKeyedCollection<string, DispatchOperation>
  41. {
  42. protected override string GetKeyForItem (DispatchOperation o)
  43. {
  44. return o.Name;
  45. }
  46. }
  47. DispatchRuntime parent;
  48. string name, action, reply_action;
  49. bool serialize_reply = true, deserialize_request = true,
  50. is_oneway, is_terminating,
  51. release_after_call, release_before_call,
  52. tx_auto_complete, tx_required,
  53. auto_dispose_params = true;
  54. IDispatchMessageFormatter formatter;
  55. #if !MOBILE
  56. ImpersonationOption impersonation;
  57. IOperationInvoker invoker;
  58. SynchronizedCollection<IParameterInspector> inspectors
  59. = new SynchronizedCollection<IParameterInspector> ();
  60. SynchronizedCollection<FaultContractInfo> fault_contract_infos
  61. = new SynchronizedCollection<FaultContractInfo> ();
  62. SynchronizedCollection<ICallContextInitializer> ctx_initializers
  63. = new SynchronizedCollection<ICallContextInitializer> ();
  64. #endif
  65. public DispatchOperation (DispatchRuntime parent,
  66. string name, string action)
  67. {
  68. if (parent == null)
  69. throw new ArgumentNullException ("parent");
  70. if (name == null)
  71. throw new ArgumentNullException ("name");
  72. // action could be null
  73. is_oneway = true;
  74. this.parent = parent;
  75. this.name = name;
  76. this.action = action;
  77. }
  78. public DispatchOperation (DispatchRuntime parent,
  79. string name, string action, string replyAction)
  80. : this (parent, name, action)
  81. {
  82. // replyAction could be null
  83. is_oneway = false;
  84. reply_action = replyAction;
  85. }
  86. public string Action {
  87. get { return action; }
  88. }
  89. #if !MOBILE
  90. public SynchronizedCollection<ICallContextInitializer> CallContextInitializers {
  91. get { return ctx_initializers; }
  92. }
  93. public SynchronizedCollection<FaultContractInfo> FaultContractInfos {
  94. get { return fault_contract_infos; }
  95. }
  96. [MonoTODO ("not considered")]
  97. public ImpersonationOption Impersonation {
  98. get { return impersonation; }
  99. set {
  100. ThrowIfOpened ();
  101. impersonation = value;
  102. }
  103. }
  104. public IOperationInvoker Invoker {
  105. get { return invoker; }
  106. set {
  107. ThrowIfOpened ();
  108. invoker = value;
  109. }
  110. }
  111. public bool IsTerminating {
  112. get { return is_terminating; }
  113. set {
  114. ThrowIfOpened ();
  115. is_terminating = value;
  116. }
  117. }
  118. public SynchronizedCollection<IParameterInspector> ParameterInspectors {
  119. get { return inspectors; }
  120. }
  121. public bool ReleaseInstanceAfterCall {
  122. get { return release_after_call; }
  123. set {
  124. ThrowIfOpened ();
  125. release_after_call = value;
  126. }
  127. }
  128. public bool ReleaseInstanceBeforeCall {
  129. get { return release_before_call; }
  130. set {
  131. ThrowIfOpened ();
  132. release_before_call = value;
  133. }
  134. }
  135. public string ReplyAction {
  136. get { return reply_action; }
  137. }
  138. public bool TransactionAutoComplete {
  139. get { return tx_auto_complete; }
  140. set {
  141. ThrowIfOpened ();
  142. tx_auto_complete = value;
  143. }
  144. }
  145. public bool TransactionRequired {
  146. get { return tx_required; }
  147. set {
  148. ThrowIfOpened ();
  149. tx_required = value;
  150. }
  151. }
  152. #endif
  153. public bool AutoDisposeParameters {
  154. get { return auto_dispose_params; }
  155. set {
  156. ThrowIfOpened ();
  157. auto_dispose_params = value;
  158. }
  159. }
  160. public bool DeserializeRequest {
  161. get { return deserialize_request; }
  162. set {
  163. ThrowIfOpened ();
  164. deserialize_request = value;
  165. }
  166. }
  167. public IDispatchMessageFormatter Formatter {
  168. get { return formatter; }
  169. set {
  170. ThrowIfOpened ();
  171. formatter = value;
  172. }
  173. }
  174. public bool IsOneWay {
  175. get { return is_oneway; }
  176. }
  177. public string Name {
  178. get { return name; }
  179. }
  180. public DispatchRuntime Parent {
  181. get { return parent; }
  182. }
  183. public bool SerializeReply {
  184. get { return serialize_reply; }
  185. set {
  186. ThrowIfOpened ();
  187. serialize_reply = value;
  188. }
  189. }
  190. void ThrowIfOpened ()
  191. {
  192. #if !MOBILE && !XAMMAC_4_5
  193. // FIXME: get callback client runtime status when ChannelDispatcher is not available.
  194. var state = Parent.ChannelDispatcher != null ? Parent.ChannelDispatcher.State : CommunicationState.Created; // Parent.CallbackClientRuntime.ChannelFactory.State;
  195. switch (state) {
  196. case CommunicationState.Created:
  197. case CommunicationState.Opening:
  198. return;
  199. }
  200. throw new InvalidOperationException ("Cannot change this property after the service host is opened");
  201. #endif
  202. }
  203. }
  204. }