It should not fail to generate client proxy generation for having two "IsRequest...
[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         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
54                 ClientRuntime parent;
55                 string name, action, reply_action;
56                 MethodInfo sync_method, begin_method, end_method;
57                 bool deserialize_reply = true, serialize_request = true;
58                 bool is_initiating, is_terminating, is_oneway;
59                 IClientMessageFormatter formatter;
60                 SynchronizedCollection<IParameterInspector> inspectors
61                         = new SynchronizedCollection<IParameterInspector> ();
62 #if !NET_2_1
63                 SynchronizedCollection<FaultContractInfo> fault_contract_infos = new SynchronizedCollection<FaultContractInfo> ();
64 #endif
65
66                 public ClientOperation (ClientRuntime parent,
67                         string name, string action)
68                 {
69                         this.parent = parent;
70                         this.name = name;
71                         this.action = action;
72                 }
73
74                 public ClientOperation (ClientRuntime parent,
75                         string name, string action, string replyAction)
76                 {
77                         this.parent = parent;
78                         this.name = name;
79                         this.action = action;
80                         this.reply_action = replyAction;
81                 }
82
83                 public string Action {
84                         get { return action; }
85                 }
86
87                 public string ReplyAction {
88                         get { return reply_action; }
89                 }
90
91                 public MethodInfo BeginMethod {
92                         get { return begin_method; }
93                         set {
94                                 ThrowIfOpened ();
95                                 begin_method = value;
96                         }
97                 }
98
99                 public bool DeserializeReply {
100                         get { return deserialize_reply; }
101                         set {
102                                 ThrowIfOpened ();
103                                 deserialize_reply = value;
104                         }
105                 }
106
107                 public MethodInfo EndMethod {
108                         get { return end_method; }
109                         set {
110                                 ThrowIfOpened ();
111                                 end_method = value;
112                         }
113                 }
114
115 #if !NET_2_1
116                 public SynchronizedCollection<FaultContractInfo> FaultContractInfos {
117                         get { return fault_contract_infos; }
118                 }
119 #endif
120
121                 public IClientMessageFormatter Formatter {
122                         get { return formatter; }
123                         set {
124                                 ThrowIfOpened ();
125                                 formatter = value;
126                         }
127                 }
128
129                 public bool IsInitiating {
130                         get { return is_initiating; }
131                         set {
132                                 ThrowIfOpened ();
133                                 is_initiating = value;
134                         }
135                 }
136
137                 public bool IsOneWay {
138                         get { return is_oneway; }
139                         set {
140                                 ThrowIfOpened ();
141                                 is_oneway = value;
142                         }
143                 }
144
145                 public bool IsTerminating {
146                         get { return is_terminating; }
147                         set {
148                                 ThrowIfOpened ();
149                                 is_terminating = value;
150                         }
151                 }
152
153                 public string Name {
154                         get { return name; }
155                 }
156
157                 public SynchronizedCollection<IParameterInspector> ParameterInspectors {
158                         get { return inspectors; }
159                 }
160
161                 public ClientRuntime Parent {
162                         get { return parent; }
163                 }
164
165                 public bool SerializeRequest {
166                         get { return serialize_request; }
167                         set {
168                                 ThrowIfOpened ();
169                                 serialize_request = value;
170                         }
171                 }
172
173                 public MethodInfo SyncMethod {
174                         get { return sync_method; }
175                         set {
176                                 ThrowIfOpened ();
177                                 sync_method = value;
178                         }
179                 }
180
181                 void ThrowIfOpened ()
182                 {
183                         // FIXME: get correct state
184                         var state = CommunicationState.Created;
185                         switch (state) {
186                         case CommunicationState.Created:
187                         case CommunicationState.Opening:
188                                 return;
189                         }
190                         throw new InvalidOperationException ("Cannot change this property after the service host is opened");
191                 }
192         }
193 }