ClientOperation.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 NET_2_1
  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. #if !NET_2_1
  61. SynchronizedCollection<FaultContractInfo> fault_contract_infos = new SynchronizedCollection<FaultContractInfo> ();
  62. #endif
  63. public ClientOperation (ClientRuntime parent,
  64. string name, string action)
  65. {
  66. this.parent = parent;
  67. this.name = name;
  68. this.action = action;
  69. }
  70. public ClientOperation (ClientRuntime parent,
  71. string name, string action, string replyAction)
  72. {
  73. this.parent = parent;
  74. this.name = name;
  75. this.action = action;
  76. this.reply_action = replyAction;
  77. }
  78. public string Action {
  79. get { return action; }
  80. }
  81. public string ReplyAction {
  82. get { return reply_action; }
  83. }
  84. public MethodInfo BeginMethod {
  85. get { return begin_method; }
  86. set {
  87. ThrowIfOpened ();
  88. begin_method = value;
  89. }
  90. }
  91. public bool DeserializeReply {
  92. get { return deserialize_reply; }
  93. set {
  94. ThrowIfOpened ();
  95. deserialize_reply = value;
  96. }
  97. }
  98. public MethodInfo EndMethod {
  99. get { return end_method; }
  100. set {
  101. ThrowIfOpened ();
  102. end_method = value;
  103. }
  104. }
  105. #if !NET_2_1
  106. public SynchronizedCollection<FaultContractInfo> FaultContractInfos {
  107. get { return fault_contract_infos; }
  108. }
  109. #endif
  110. public IClientMessageFormatter Formatter {
  111. get { return formatter; }
  112. set {
  113. ThrowIfOpened ();
  114. formatter = value;
  115. }
  116. }
  117. public bool IsInitiating {
  118. get { return is_initiating; }
  119. set {
  120. ThrowIfOpened ();
  121. is_initiating = value;
  122. }
  123. }
  124. public bool IsOneWay {
  125. get { return is_oneway; }
  126. set {
  127. ThrowIfOpened ();
  128. is_oneway = value;
  129. }
  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 ClientRuntime Parent {
  145. get { return parent; }
  146. }
  147. public bool SerializeRequest {
  148. get { return serialize_request; }
  149. set {
  150. ThrowIfOpened ();
  151. serialize_request = value;
  152. }
  153. }
  154. public MethodInfo SyncMethod {
  155. get { return sync_method; }
  156. set {
  157. ThrowIfOpened ();
  158. sync_method = value;
  159. }
  160. }
  161. void ThrowIfOpened ()
  162. {
  163. // FIXME: get correct state
  164. var state = CommunicationState.Created;
  165. switch (state) {
  166. case CommunicationState.Created:
  167. case CommunicationState.Opening:
  168. return;
  169. }
  170. throw new InvalidOperationException ("Cannot change this property after the service host is opened");
  171. }
  172. }
  173. }