5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2005 Novell, Inc. http://www.novell.com
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
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;
37 namespace System.ServiceModel.Dispatcher
40 public sealed class ClientOperation
42 internal class ClientOperationCollection :
44 KeyedCollection<string, ClientOperation>
46 SynchronizedKeyedCollection<string, ClientOperation>
49 protected override string GetKeyForItem (ClientOperation o)
56 string name, action, reply_action;
57 MethodInfo sync_method, begin_method, end_method;
58 bool deserialize_reply = true, serialize_request = true;
59 bool is_initiating, is_terminating, is_oneway;
60 IClientMessageFormatter formatter, actual_formatter;
61 SynchronizedCollection<IParameterInspector> inspectors
62 = new SynchronizedCollection<IParameterInspector> ();
64 SynchronizedCollection<FaultContractInfo> fault_contract_infos;
67 public ClientOperation (ClientRuntime parent,
68 string name, string action)
75 public ClientOperation (ClientRuntime parent,
76 string name, string action, string replyAction)
81 this.reply_action = replyAction;
84 public string Action {
85 get { return action; }
88 public string ReplyAction {
89 get { return reply_action; }
92 public MethodInfo BeginMethod {
93 get { return begin_method; }
94 set { begin_method = value; }
97 public bool DeserializeReply {
98 get { return deserialize_reply; }
99 set { deserialize_reply = value; }
102 public MethodInfo EndMethod {
103 get { return end_method; }
104 set { end_method = value; }
108 public SynchronizedCollection<FaultContractInfo> FaultContractInfos {
110 if (fault_contract_infos == null) {
111 var l = new SynchronizedCollection<FaultContractInfo> ();
112 foreach (var f in Description.Faults)
113 l.Add (new FaultContractInfo (f.Action, f.DetailType));
114 fault_contract_infos = l;
116 return fault_contract_infos;
121 public IClientMessageFormatter Formatter {
122 get { return formatter; }
123 set { formatter = value; }
126 public bool IsInitiating {
127 get { return is_initiating; }
128 set { is_initiating = value; }
131 public bool IsOneWay {
132 get { return is_oneway; }
133 set { is_oneway = value; }
136 public bool IsTerminating {
137 get { return is_terminating; }
138 set { is_terminating = value; }
145 public SynchronizedCollection<IParameterInspector> ParameterInspectors {
146 get { return inspectors; }
149 public ClientRuntime Parent {
150 get { return parent; }
153 public bool SerializeRequest {
154 get { return serialize_request; }
155 set { serialize_request = value; }
158 public MethodInfo SyncMethod {
159 get { return sync_method; }
160 set { sync_method = value; }
163 OperationDescription Description {
165 // FIXME: ContractDescription should be acquired from elsewhere.
166 ContractDescription cd = ContractDescription.GetContract (Parent.ContractClientType);
167 OperationDescription od = cd.Operations.Find (Name);
170 throw new Exception (String.Format ("INTERNAL ERROR: Contract {0} in namespace {1} does not contain Operations.", Parent.ContractName, Parent.ContractNamespace));
172 throw new Exception (String.Format ("INTERNAL ERROR: Operation {0} was not found.", Name));
178 internal IClientMessageFormatter GetFormatter ()
180 if (actual_formatter == null) {
181 if (Formatter != null)
182 actual_formatter = Formatter;
184 actual_formatter = new OperationFormatter (Description, false, false); // FIXME: pass correct isRpc, isEncoded
186 return actual_formatter;