DispatchOperation.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. //
  2. // DispatchOperation.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2005 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. [MonoTODO]
  38. public sealed class DispatchOperation
  39. {
  40. internal class DispatchOperationCollection :
  41. SynchronizedKeyedCollection<string, DispatchOperation>
  42. {
  43. protected override string GetKeyForItem (DispatchOperation o)
  44. {
  45. return o.Name;
  46. }
  47. }
  48. DispatchRuntime parent;
  49. string name, action, reply_action;
  50. bool serialize_reply = true, deserialize_request = true,
  51. is_oneway, is_terminating,
  52. release_after_call, release_before_call,
  53. tx_auto_complete, tx_required,
  54. auto_dispose_params = true;
  55. ImpersonationOption impersonation;
  56. IDispatchMessageFormatter formatter, actual_formatter;
  57. IOperationInvoker invoker;
  58. SynchronizedCollection<IParameterInspector> inspectors
  59. = new SynchronizedCollection<IParameterInspector> ();
  60. SynchronizedCollection<FaultContractInfo> fault_contract_infos;
  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 { auto_dispose_params = value; }
  93. }
  94. public bool DeserializeRequest {
  95. get { return deserialize_request; }
  96. set { deserialize_request = value; }
  97. }
  98. public SynchronizedCollection<FaultContractInfo> FaultContractInfos {
  99. get {
  100. if (fault_contract_infos == null) {
  101. var l = new SynchronizedCollection<FaultContractInfo> ();
  102. foreach (var f in Description.Faults)
  103. l.Add (new FaultContractInfo (f.Action, f.DetailType));
  104. fault_contract_infos = l;
  105. }
  106. return fault_contract_infos;
  107. }
  108. }
  109. public IDispatchMessageFormatter Formatter {
  110. get { return formatter; }
  111. set {
  112. formatter = value;
  113. actual_formatter = null;
  114. }
  115. }
  116. public ImpersonationOption Impersonation {
  117. get { return impersonation; }
  118. set { impersonation = value; }
  119. }
  120. public IOperationInvoker Invoker {
  121. get { return invoker; }
  122. set { invoker = value; }
  123. }
  124. public bool IsOneWay {
  125. get { return is_oneway; }
  126. }
  127. public bool IsTerminating {
  128. get { return is_terminating; }
  129. set { is_terminating = value; }
  130. }
  131. public string Name {
  132. get { return name; }
  133. }
  134. public SynchronizedCollection<IParameterInspector> ParameterInspectors {
  135. get { return inspectors; }
  136. }
  137. public DispatchRuntime Parent {
  138. get { return parent; }
  139. }
  140. public bool ReleaseInstanceAfterCall {
  141. get { return release_after_call; }
  142. set { release_after_call = value; }
  143. }
  144. public bool ReleaseInstanceBeforeCall {
  145. get { return release_before_call; }
  146. set { release_before_call = value; }
  147. }
  148. public string ReplyAction {
  149. get { return reply_action; }
  150. }
  151. public bool SerializeReply {
  152. get { return serialize_reply; }
  153. set { serialize_reply = value; }
  154. }
  155. public bool TransactionAutoComplete {
  156. get { return tx_auto_complete; }
  157. set { tx_auto_complete = value; }
  158. }
  159. public bool TransactionRequired {
  160. get { return tx_required; }
  161. set { tx_required = value; }
  162. }
  163. MessageVersion MessageVersion {
  164. get { return Parent.ChannelDispatcher.MessageVersion; }
  165. }
  166. OperationDescription Description {
  167. get {
  168. // FIXME: ContractDescription should be acquired from elsewhere.
  169. ContractDescription cd = ContractDescription.GetContract (Parent.Type);
  170. OperationDescription od = cd.Operations.Find (Name);
  171. if (od == null) {
  172. if (Name == "*")
  173. throw new Exception (String.Format ("INTERNAL ERROR: Contract {0} in namespace {1} does not contain Operations.", Parent.EndpointDispatcher.ContractName, Parent.EndpointDispatcher.ContractNamespace));
  174. else
  175. throw new Exception (String.Format ("INTERNAL ERROR: Operation {0} was not found.", Name));
  176. }
  177. return od;
  178. }
  179. }
  180. internal IDispatchMessageFormatter GetFormatter ()
  181. {
  182. if (actual_formatter == null) {
  183. if (Formatter != null)
  184. actual_formatter = Formatter;
  185. else
  186. actual_formatter = BaseMessagesFormatter.Create (Description);
  187. }
  188. return actual_formatter;
  189. }
  190. }
  191. }