ClientOperation.cs 4.7 KB

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