Add support for ToolsVersion and correctly build msbuild+xbuild assemblies
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Dispatcher / ClientOperation.cs
1 //
2 // ClientOperation.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
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
37 namespace System.ServiceModel.Dispatcher
38 {
39         [MonoTODO]
40         public sealed class ClientOperation
41         {
42                 internal class ClientOperationCollection :
43 #if NET_2_1
44                         KeyedCollection<string, ClientOperation>
45 #else
46                         SynchronizedKeyedCollection<string, ClientOperation>
47 #endif
48                 {
49                         protected override string GetKeyForItem (ClientOperation o)
50                         {
51                                 return o.Name;
52                         }
53                 }
54
55                 ClientRuntime parent;
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> ();
63 #if !NET_2_1
64                 SynchronizedCollection<FaultContractInfo> fault_contract_infos = new SynchronizedCollection<FaultContractInfo> ();
65 #endif
66
67                 public ClientOperation (ClientRuntime parent,
68                         string name, string action)
69                 {
70                         this.parent = parent;
71                         this.name = name;
72                         this.action = action;
73                 }
74
75                 public ClientOperation (ClientRuntime parent,
76                         string name, string action, string replyAction)
77                 {
78                         this.parent = parent;
79                         this.name = name;
80                         this.action = action;
81                         this.reply_action = replyAction;
82                 }
83
84                 public string Action {
85                         get { return action; }
86                 }
87
88                 public string ReplyAction {
89                         get { return reply_action; }
90                 }
91
92                 public MethodInfo BeginMethod {
93                         get { return begin_method; }
94                         set { begin_method = value; }
95                 }
96
97                 public bool DeserializeReply {
98                         get { return deserialize_reply; }
99                         set { deserialize_reply = value; }
100                 }
101
102                 public MethodInfo EndMethod {
103                         get { return end_method; }
104                         set { end_method = value; }
105                 }
106
107 #if !NET_2_1
108                 public SynchronizedCollection<FaultContractInfo> FaultContractInfos {
109                         get { return fault_contract_infos; }
110                 }
111 #endif
112
113                 public IClientMessageFormatter Formatter {
114                         get { return formatter; }
115                         set { formatter = value; }
116                 }
117
118                 public bool IsInitiating {
119                         get { return is_initiating; }
120                         set { is_initiating = value; }
121                 }
122
123                 public bool IsOneWay {
124                         get { return is_oneway; }
125                         set { is_oneway = value; }
126                 }
127
128                 public bool IsTerminating {
129                         get { return is_terminating; }
130                         set { is_terminating = value; }
131                 }
132
133                 public string Name {
134                         get { return name; }
135                 }
136
137                 public SynchronizedCollection<IParameterInspector> ParameterInspectors {
138                         get { return inspectors; }
139                 }
140
141                 public ClientRuntime Parent {
142                         get { return parent; }
143                 }
144
145                 public bool SerializeRequest {
146                         get { return serialize_request; }
147                         set { serialize_request = value; }
148                 }
149
150                 public MethodInfo SyncMethod {
151                         get { return sync_method; }
152                         set { sync_method = value; }
153                 }
154
155                 OperationDescription Description {
156                         get {
157                                 // FIXME: ContractDescription should be acquired from elsewhere.
158                                 ContractDescription cd = ContractDescription.GetContract (Parent.ContractClientType);
159                                 OperationDescription od = cd.Operations.Find (Name);
160                                 if (od == null) {
161                                         if (Name == "*")
162                                                 throw new Exception (String.Format ("INTERNAL ERROR: Contract {0} in namespace {1} does not contain Operations.", Parent.ContractName, Parent.ContractNamespace));
163                                         else
164                                                 throw new Exception (String.Format ("INTERNAL ERROR: Operation {0} was not found.", Name));
165                                 }
166                                 return od;
167                         }
168                 }
169
170                 internal IClientMessageFormatter GetFormatter ()
171                 {
172                         if (actual_formatter == null) {
173                                 if (Formatter != null)
174                                         actual_formatter = Formatter;
175                                 else
176                                         actual_formatter = new OperationFormatter (Description, false, false); // FIXME: pass correct isRpc, isEncoded
177                         }
178                         return actual_formatter;
179                 }
180         }
181 }