2
0

DispatchOperation.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. = new SynchronizedCollection<FaultContractInfo> ();
  62. SynchronizedCollection<ICallContextInitializer> ctx_initializers
  63. = new SynchronizedCollection<ICallContextInitializer> ();
  64. public DispatchOperation (DispatchRuntime parent,
  65. string name, string action)
  66. {
  67. if (parent == null)
  68. throw new ArgumentNullException ("parent");
  69. if (name == null)
  70. throw new ArgumentNullException ("name");
  71. // action could be null
  72. is_oneway = true;
  73. this.parent = parent;
  74. this.name = name;
  75. this.action = action;
  76. }
  77. public DispatchOperation (DispatchRuntime parent,
  78. string name, string action, string replyAction)
  79. : this (parent, name, action)
  80. {
  81. // replyAction could be null
  82. is_oneway = false;
  83. reply_action = replyAction;
  84. }
  85. public string Action {
  86. get { return action; }
  87. }
  88. public SynchronizedCollection<ICallContextInitializer> CallContextInitializers {
  89. get { return ctx_initializers; }
  90. }
  91. public bool AutoDisposeParameters {
  92. get { return auto_dispose_params; }
  93. set { auto_dispose_params = value; }
  94. }
  95. public bool DeserializeRequest {
  96. get { return deserialize_request; }
  97. set { deserialize_request = value; }
  98. }
  99. public SynchronizedCollection<FaultContractInfo> FaultContractInfos {
  100. get { return fault_contract_infos; }
  101. }
  102. public IDispatchMessageFormatter Formatter {
  103. get { return formatter; }
  104. set {
  105. formatter = value;
  106. actual_formatter = null;
  107. }
  108. }
  109. public ImpersonationOption Impersonation {
  110. get { return impersonation; }
  111. set { impersonation = value; }
  112. }
  113. public IOperationInvoker Invoker {
  114. get { return invoker; }
  115. set { invoker = value; }
  116. }
  117. public bool IsOneWay {
  118. get { return is_oneway; }
  119. }
  120. public bool IsTerminating {
  121. get { return is_terminating; }
  122. set { is_terminating = value; }
  123. }
  124. public string Name {
  125. get { return name; }
  126. }
  127. public SynchronizedCollection<IParameterInspector> ParameterInspectors {
  128. get { return inspectors; }
  129. }
  130. public DispatchRuntime Parent {
  131. get { return parent; }
  132. }
  133. public bool ReleaseInstanceAfterCall {
  134. get { return release_after_call; }
  135. set { release_after_call = value; }
  136. }
  137. public bool ReleaseInstanceBeforeCall {
  138. get { return release_before_call; }
  139. set { release_before_call = value; }
  140. }
  141. public string ReplyAction {
  142. get { return reply_action; }
  143. }
  144. public bool SerializeReply {
  145. get { return serialize_reply; }
  146. set { serialize_reply = value; }
  147. }
  148. public bool TransactionAutoComplete {
  149. get { return tx_auto_complete; }
  150. set { tx_auto_complete = value; }
  151. }
  152. public bool TransactionRequired {
  153. get { return tx_required; }
  154. set { tx_required = value; }
  155. }
  156. MessageVersion MessageVersion {
  157. get { return Parent.ChannelDispatcher.MessageVersion; }
  158. }
  159. OperationDescription Description {
  160. get {
  161. // FIXME: ContractDescription should be acquired from elsewhere.
  162. ContractDescription cd = ContractDescription.GetContract (Parent.Type);
  163. OperationDescription od = cd.Operations.Find (Name);
  164. if (od == null) {
  165. if (Name == "*")
  166. throw new Exception (String.Format ("INTERNAL ERROR: Contract {0} in namespace {1} does not contain Operations.", Parent.EndpointDispatcher.ContractName, Parent.EndpointDispatcher.ContractNamespace));
  167. else
  168. throw new Exception (String.Format ("INTERNAL ERROR: Operation {0} was not found.", Name));
  169. }
  170. return od;
  171. }
  172. }
  173. internal IDispatchMessageFormatter GetFormatter ()
  174. {
  175. if (actual_formatter == null) {
  176. if (Formatter != null)
  177. actual_formatter = Formatter;
  178. else
  179. actual_formatter = new OperationFormatter (Description, false, false); // FIXME: pass correct isRpc, isEncoded
  180. }
  181. return actual_formatter;
  182. }
  183. }
  184. }