ClientOperation.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. //
  2. // ClientOperation.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.Collections.ObjectModel;
  31. using System.Reflection;
  32. using System.ServiceModel;
  33. using System.ServiceModel.Channels;
  34. using System.ServiceModel.Description;
  35. using System.Text;
  36. namespace System.ServiceModel.Dispatcher
  37. {
  38. public sealed class ClientOperation
  39. {
  40. internal class ClientOperationCollection :
  41. #if MOBILE
  42. KeyedCollection<string, ClientOperation>
  43. #else
  44. SynchronizedKeyedCollection<string, ClientOperation>
  45. #endif
  46. {
  47. protected override string GetKeyForItem (ClientOperation o)
  48. {
  49. return o.Name;
  50. }
  51. }
  52. ClientRuntime parent;
  53. string name, action, reply_action;
  54. MethodInfo sync_method, begin_method, end_method;
  55. bool deserialize_reply = true, serialize_request = true;
  56. bool is_initiating, is_terminating, is_oneway;
  57. IClientMessageFormatter formatter;
  58. SynchronizedCollection<IParameterInspector> inspectors
  59. = new SynchronizedCollection<IParameterInspector> ();
  60. SynchronizedCollection<FaultContractInfo> fault_contract_infos = new SynchronizedCollection<FaultContractInfo> ();
  61. public ClientOperation (ClientRuntime parent,
  62. string name, string action)
  63. {
  64. this.parent = parent;
  65. this.name = name;
  66. this.action = action;
  67. }
  68. public ClientOperation (ClientRuntime parent,
  69. string name, string action, string replyAction)
  70. {
  71. this.parent = parent;
  72. this.name = name;
  73. this.action = action;
  74. this.reply_action = replyAction;
  75. }
  76. public string Action {
  77. get { return action; }
  78. }
  79. public string ReplyAction {
  80. get { return reply_action; }
  81. }
  82. public MethodInfo BeginMethod {
  83. get { return begin_method; }
  84. set {
  85. ThrowIfOpened ();
  86. begin_method = value;
  87. }
  88. }
  89. public bool DeserializeReply {
  90. get { return deserialize_reply; }
  91. set {
  92. ThrowIfOpened ();
  93. deserialize_reply = value;
  94. }
  95. }
  96. public MethodInfo EndMethod {
  97. get { return end_method; }
  98. set {
  99. ThrowIfOpened ();
  100. end_method = value;
  101. }
  102. }
  103. public SynchronizedCollection<FaultContractInfo> FaultContractInfos {
  104. get { return fault_contract_infos; }
  105. }
  106. public IClientMessageFormatter Formatter {
  107. get { return formatter; }
  108. set {
  109. ThrowIfOpened ();
  110. formatter = value;
  111. }
  112. }
  113. public bool IsInitiating {
  114. get { return is_initiating; }
  115. set {
  116. ThrowIfOpened ();
  117. is_initiating = value;
  118. }
  119. }
  120. public bool IsOneWay {
  121. get { return is_oneway; }
  122. set {
  123. ThrowIfOpened ();
  124. is_oneway = value;
  125. }
  126. }
  127. public bool IsTerminating {
  128. get { return is_terminating; }
  129. set {
  130. ThrowIfOpened ();
  131. is_terminating = value;
  132. }
  133. }
  134. public string Name {
  135. get { return name; }
  136. }
  137. public SynchronizedCollection<IParameterInspector> ParameterInspectors {
  138. get { return inspectors; }
  139. }
  140. public ClientRuntime Parent {
  141. get { return parent; }
  142. }
  143. public bool SerializeRequest {
  144. get { return serialize_request; }
  145. set {
  146. ThrowIfOpened ();
  147. serialize_request = value;
  148. }
  149. }
  150. public MethodInfo SyncMethod {
  151. get { return sync_method; }
  152. set {
  153. ThrowIfOpened ();
  154. sync_method = value;
  155. }
  156. }
  157. void ThrowIfOpened ()
  158. {
  159. // FIXME: get correct state
  160. var state = CommunicationState.Created;
  161. switch (state) {
  162. case CommunicationState.Created:
  163. case CommunicationState.Opening:
  164. return;
  165. }
  166. throw new InvalidOperationException ("Cannot change this property after the service host is opened");
  167. }
  168. [MonoTODO]
  169. public ICollection<IParameterInspector> ClientParameterInspectors {
  170. get { throw new NotImplementedException (); }
  171. }
  172. [MonoTODO]
  173. public MethodInfo TaskMethod {
  174. get { throw new NotImplementedException (); }
  175. set { throw new NotImplementedException (); }
  176. }
  177. [MonoTODO]
  178. public Type TaskTResult {
  179. get { throw new NotImplementedException (); }
  180. set { throw new NotImplementedException (); }
  181. }
  182. }
  183. }