ClientOperation.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. public SynchronizedCollection<FaultContractInfo> FaultContractInfos {
  90. get { throw new NotImplementedException (); }
  91. }
  92. public IClientMessageFormatter Formatter {
  93. get { return formatter; }
  94. set { formatter = value; }
  95. }
  96. public bool IsInitiating {
  97. get { return is_initiating; }
  98. set { is_initiating = value; }
  99. }
  100. public bool IsOneWay {
  101. get { return is_oneway; }
  102. set { is_oneway = value; }
  103. }
  104. public bool IsTerminating {
  105. get { return is_terminating; }
  106. set { is_terminating = value; }
  107. }
  108. public string Name {
  109. get { return name; }
  110. }
  111. public SynchronizedCollection<IParameterInspector> ParameterInspectors {
  112. get { return inspectors; }
  113. }
  114. public ClientRuntime Parent {
  115. get { return parent; }
  116. }
  117. public bool SerializeRequest {
  118. get { return serialize_request; }
  119. set { serialize_request = value; }
  120. }
  121. public MethodInfo SyncMethod {
  122. get { return sync_method; }
  123. set { sync_method = value; }
  124. }
  125. OperationDescription Description {
  126. get {
  127. // FIXME: ContractDescription should be acquired from elsewhere.
  128. ContractDescription cd = ContractDescription.GetContract (Parent.ContractClientType);
  129. OperationDescription od = cd.Operations.Find (Name);
  130. if (od == null) {
  131. if (Name == "*")
  132. throw new Exception (String.Format ("INTERNAL ERROR: Contract {0} in namespace {1} does not contain Operations.", Parent.ContractName, Parent.ContractNamespace));
  133. else
  134. throw new Exception (String.Format ("INTERNAL ERROR: Operation {0} was not found.", Name));
  135. }
  136. return od;
  137. }
  138. }
  139. internal IClientMessageFormatter GetFormatter ()
  140. {
  141. if (actual_formatter == null) {
  142. if (Formatter != null)
  143. actual_formatter = Formatter;
  144. else
  145. actual_formatter = BaseMessagesFormatter.Create (Description);
  146. }
  147. return actual_formatter;
  148. }
  149. }
  150. }