ClientOperation.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. [MonoTODO]
  39. public sealed class ClientOperation
  40. {
  41. internal class ClientOperationCollection :
  42. #if NET_2_1
  43. KeyedCollection<string, ClientOperation>
  44. #else
  45. SynchronizedKeyedCollection<string, ClientOperation>
  46. #endif
  47. {
  48. protected override string GetKeyForItem (ClientOperation o)
  49. {
  50. return o.Name;
  51. }
  52. }
  53. ClientRuntime parent;
  54. string name, action, reply_action;
  55. MethodInfo sync_method, begin_method, end_method;
  56. bool deserialize_reply = true, serialize_request = true;
  57. bool is_initiating, is_terminating, is_oneway;
  58. IClientMessageFormatter formatter, actual_formatter;
  59. SynchronizedCollection<IParameterInspector> inspectors
  60. = new SynchronizedCollection<IParameterInspector> ();
  61. #if !NET_2_1
  62. SynchronizedCollection<FaultContractInfo> fault_contract_infos;
  63. #endif
  64. public ClientOperation (ClientRuntime parent,
  65. string name, string action)
  66. {
  67. this.parent = parent;
  68. this.name = name;
  69. this.action = action;
  70. }
  71. public ClientOperation (ClientRuntime parent,
  72. string name, string action, string replyAction)
  73. {
  74. this.parent = parent;
  75. this.name = name;
  76. this.action = action;
  77. this.reply_action = replyAction;
  78. }
  79. public string Action {
  80. get { return action; }
  81. }
  82. public string ReplyAction {
  83. get { return reply_action; }
  84. }
  85. public MethodInfo BeginMethod {
  86. get { return begin_method; }
  87. set { begin_method = value; }
  88. }
  89. public bool DeserializeReply {
  90. get { return deserialize_reply; }
  91. set { deserialize_reply = value; }
  92. }
  93. public MethodInfo EndMethod {
  94. get { return end_method; }
  95. set { end_method = value; }
  96. }
  97. #if !NET_2_1
  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. #endif
  110. public IClientMessageFormatter Formatter {
  111. get { return formatter; }
  112. set { formatter = value; }
  113. }
  114. public bool IsInitiating {
  115. get { return is_initiating; }
  116. set { is_initiating = value; }
  117. }
  118. public bool IsOneWay {
  119. get { return is_oneway; }
  120. set { is_oneway = value; }
  121. }
  122. public bool IsTerminating {
  123. get { return is_terminating; }
  124. set { is_terminating = value; }
  125. }
  126. public string Name {
  127. get { return name; }
  128. }
  129. public SynchronizedCollection<IParameterInspector> ParameterInspectors {
  130. get { return inspectors; }
  131. }
  132. public ClientRuntime Parent {
  133. get { return parent; }
  134. }
  135. public bool SerializeRequest {
  136. get { return serialize_request; }
  137. set { serialize_request = value; }
  138. }
  139. public MethodInfo SyncMethod {
  140. get { return sync_method; }
  141. set { sync_method = value; }
  142. }
  143. OperationDescription Description {
  144. get {
  145. // FIXME: ContractDescription should be acquired from elsewhere.
  146. ContractDescription cd = ContractDescription.GetContract (Parent.ContractClientType);
  147. OperationDescription od = cd.Operations.Find (Name);
  148. if (od == null) {
  149. if (Name == "*")
  150. throw new Exception (String.Format ("INTERNAL ERROR: Contract {0} in namespace {1} does not contain Operations.", Parent.ContractName, Parent.ContractNamespace));
  151. else
  152. throw new Exception (String.Format ("INTERNAL ERROR: Operation {0} was not found.", Name));
  153. }
  154. return od;
  155. }
  156. }
  157. internal IClientMessageFormatter GetFormatter ()
  158. {
  159. if (actual_formatter == null) {
  160. if (Formatter != null)
  161. actual_formatter = Formatter;
  162. else
  163. actual_formatter = BaseMessagesFormatter.Create (Description);
  164. }
  165. return actual_formatter;
  166. }
  167. }
  168. }