DispatchOperation.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. ImpersonationOption impersonation;
  55. IDispatchMessageFormatter formatter;
  56. IOperationInvoker invoker;
  57. SynchronizedCollection<IParameterInspector> inspectors
  58. = new SynchronizedCollection<IParameterInspector> ();
  59. SynchronizedCollection<FaultContractInfo> fault_contract_infos
  60. = new SynchronizedCollection<FaultContractInfo> ();
  61. SynchronizedCollection<ICallContextInitializer> ctx_initializers
  62. = new SynchronizedCollection<ICallContextInitializer> ();
  63. public DispatchOperation (DispatchRuntime parent,
  64. string name, string action)
  65. {
  66. if (parent == null)
  67. throw new ArgumentNullException ("parent");
  68. if (name == null)
  69. throw new ArgumentNullException ("name");
  70. // action could be null
  71. is_oneway = true;
  72. this.parent = parent;
  73. this.name = name;
  74. this.action = action;
  75. }
  76. public DispatchOperation (DispatchRuntime parent,
  77. string name, string action, string replyAction)
  78. : this (parent, name, action)
  79. {
  80. // replyAction could be null
  81. is_oneway = false;
  82. reply_action = replyAction;
  83. }
  84. public string Action {
  85. get { return action; }
  86. }
  87. public SynchronizedCollection<ICallContextInitializer> CallContextInitializers {
  88. get { return ctx_initializers; }
  89. }
  90. public bool AutoDisposeParameters {
  91. get { return auto_dispose_params; }
  92. set {
  93. ThrowIfOpened ();
  94. auto_dispose_params = value;
  95. }
  96. }
  97. public bool DeserializeRequest {
  98. get { return deserialize_request; }
  99. set {
  100. ThrowIfOpened ();
  101. deserialize_request = value;
  102. }
  103. }
  104. public SynchronizedCollection<FaultContractInfo> FaultContractInfos {
  105. get { return fault_contract_infos; }
  106. }
  107. public IDispatchMessageFormatter Formatter {
  108. get { return formatter; }
  109. set {
  110. ThrowIfOpened ();
  111. formatter = value;
  112. }
  113. }
  114. public ImpersonationOption Impersonation {
  115. get { return impersonation; }
  116. set {
  117. ThrowIfOpened ();
  118. impersonation = value;
  119. }
  120. }
  121. public IOperationInvoker Invoker {
  122. get { return invoker; }
  123. set {
  124. ThrowIfOpened ();
  125. invoker = value;
  126. }
  127. }
  128. public bool IsOneWay {
  129. get { return is_oneway; }
  130. }
  131. public bool IsTerminating {
  132. get { return is_terminating; }
  133. set {
  134. ThrowIfOpened ();
  135. is_terminating = value;
  136. }
  137. }
  138. public string Name {
  139. get { return name; }
  140. }
  141. public SynchronizedCollection<IParameterInspector> ParameterInspectors {
  142. get { return inspectors; }
  143. }
  144. public DispatchRuntime Parent {
  145. get { return parent; }
  146. }
  147. public bool ReleaseInstanceAfterCall {
  148. get { return release_after_call; }
  149. set {
  150. ThrowIfOpened ();
  151. release_after_call = value;
  152. }
  153. }
  154. public bool ReleaseInstanceBeforeCall {
  155. get { return release_before_call; }
  156. set {
  157. ThrowIfOpened ();
  158. release_before_call = value;
  159. }
  160. }
  161. public string ReplyAction {
  162. get { return reply_action; }
  163. }
  164. public bool SerializeReply {
  165. get { return serialize_reply; }
  166. set {
  167. ThrowIfOpened ();
  168. serialize_reply = value;
  169. }
  170. }
  171. public bool TransactionAutoComplete {
  172. get { return tx_auto_complete; }
  173. set {
  174. ThrowIfOpened ();
  175. tx_auto_complete = value;
  176. }
  177. }
  178. public bool TransactionRequired {
  179. get { return tx_required; }
  180. set {
  181. ThrowIfOpened ();
  182. tx_required = value;
  183. }
  184. }
  185. void ThrowIfOpened ()
  186. {
  187. // FIXME: get callback client runtime status when ChannelDispatcher is not available.
  188. var state = Parent.ChannelDispatcher != null ? Parent.ChannelDispatcher.State : CommunicationState.Created; // Parent.CallbackClientRuntime.ChannelFactory.State;
  189. switch (state) {
  190. case CommunicationState.Created:
  191. case CommunicationState.Opening:
  192. return;
  193. }
  194. throw new InvalidOperationException ("Cannot change this property after the service host is opened");
  195. }
  196. }
  197. }