[System.ServiceModel] Rename method parameters to match .NET contract
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Channels / Binding.cs
1 //
2 // Binding.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.ServiceModel.Channels;
31 using System.ServiceModel.Description;
32
33 namespace System.ServiceModel.Channels
34 {
35         public abstract class Binding : IDefaultCommunicationTimeouts
36         {
37                 string name, ns;
38                 TimeSpan open_timeout, close_timeout;
39                 TimeSpan receive_timeout, send_timeout;
40
41                 protected Binding ()
42                 {
43                         Initialize ();
44                         name = GetType ().Name;
45                         ns = "http://tempuri.org/";
46                 }
47
48                 protected Binding (string name, string ns)
49                 {
50                         this.name = name;
51                         this.ns = ns;
52                         Initialize ();
53                 }
54
55                 public TimeSpan CloseTimeout {
56                         get { return close_timeout; }
57                         set { close_timeout = value; }
58                 }
59
60                 public TimeSpan OpenTimeout {
61                         get { return open_timeout; }
62                         set { open_timeout = value; }
63                 }
64
65                 public TimeSpan ReceiveTimeout {
66                         get { return receive_timeout; }
67                         set { receive_timeout = value; }
68                 }
69
70                 public TimeSpan SendTimeout {
71                         get { return send_timeout; }
72                         set { send_timeout = value; }
73                 }
74
75                 public string Name {
76                         get { return name; }
77                         set { name = value; }
78                 }
79
80                 public string Namespace {
81                         get { return ns; }
82                         set { ns = value; }
83                 }
84
85                 public abstract string Scheme { get; }
86
87                 public MessageVersion MessageVersion {
88                         get { return GetProperty<MessageVersion> (new BindingParameterCollection ()); }
89                 }
90
91                 BindingContext CreateContext (
92                         BindingParameterCollection parameters)
93                 {
94                         // FIXME: it seems that binding elements are
95                         // "validated" so that the last item is a transport.
96                         return new BindingContext (
97                                 new CustomBinding (this), parameters);
98                 }
99
100                 BindingContext CreateContext (
101                         Uri listenUriBaseAddress,
102                         string listenUriRelativeAddress,
103                         ListenUriMode listenUriMode,
104                         BindingParameterCollection parameters)
105                 {
106                         // FIXME: it seems that binding elements are
107                         // "validated" so that the last item is a transport.
108                         return new BindingContext (
109                                 new CustomBinding (this),
110                                 parameters,
111                                 listenUriBaseAddress,
112                                 listenUriRelativeAddress,
113                                 listenUriMode);
114                 }
115
116                 public IChannelFactory<TChannel>
117                         BuildChannelFactory<TChannel> (
118                         params object [] parameters)
119                 {
120                         BindingParameterCollection pl =
121                                 new BindingParameterCollection ();
122                         foreach (object o in parameters)
123                                 pl.Add (o);
124                         return BuildChannelFactory<TChannel> (pl);
125                 }
126
127                 public virtual IChannelFactory<TChannel>
128                         BuildChannelFactory<TChannel> (
129                         BindingParameterCollection parameters)
130                 {
131                         if (parameters == null)
132                                 throw new ArgumentNullException ("parameters");
133                         return CreateContext (parameters).BuildInnerChannelFactory<TChannel> ();
134                 }
135
136 #if !MOBILE
137                 public virtual IChannelListener<TChannel>
138                         BuildChannelListener<TChannel> (
139                         Uri listenUriBaseAddress,
140                         string listenUriRelativeAddress,
141                         ListenUriMode listenUriMode,
142                         params object [] parameters)
143                         where TChannel : class, IChannel
144                 {
145                         BindingParameterCollection pl =
146                                 new BindingParameterCollection ();
147                         foreach (object o in parameters)
148                                 pl.Add (o);
149                         return BuildChannelListener<TChannel> (
150                                 listenUriBaseAddress,
151                                 listenUriRelativeAddress,
152                                 listenUriMode,
153                                 pl);
154                 }
155
156                 public virtual IChannelListener<TChannel>
157                         BuildChannelListener<TChannel> (
158                         Uri listenUriBaseAddress,
159                         string listenUriRelativeAddress,
160                         ListenUriMode listenUriMode,
161                         BindingParameterCollection parameters)
162                         where TChannel : class, IChannel
163                 {
164                         if (listenUriBaseAddress == null)
165                                 throw new ArgumentNullException ("listenUriBaseAddress");
166                         if (listenUriRelativeAddress == null)
167                                 throw new ArgumentNullException ("listenUriRelativeAddress");
168                         if (parameters == null)
169                                 throw new ArgumentNullException ("parameters");
170                         BindingContext ctx = CreateContext (listenUriBaseAddress,
171                                 listenUriRelativeAddress,
172                                 listenUriMode,
173                                 parameters);
174                         return ctx.BuildInnerChannelListener<TChannel> ();
175                 }
176
177                 public virtual IChannelListener<TChannel>
178                         BuildChannelListener<TChannel> (
179                         Uri listenUriBaseAddress,
180                         params object [] parameters)
181                         where TChannel : class, IChannel
182                 {
183                         BindingParameterCollection pl =
184                                 new BindingParameterCollection ();
185                         foreach (object o in parameters)
186                                 pl.Add (o);
187                         return BuildChannelListener<TChannel> (listenUriBaseAddress, pl);
188                 }
189
190                 public virtual IChannelListener<TChannel>
191                         BuildChannelListener<TChannel> (
192                         Uri listenUriBaseAddress,
193                         BindingParameterCollection parameters)
194                         where TChannel : class, IChannel
195                 {
196                         return BuildChannelListener<TChannel> (listenUriBaseAddress,
197                                 String.Empty, parameters);
198                 }
199
200                 public virtual IChannelListener<TChannel>
201                         BuildChannelListener<TChannel> (
202                         Uri listenUriBaseAddress,
203                         string listenUriRelativeAddress,
204                         params object [] parameters)
205                         where TChannel : class, IChannel
206                 {
207                         BindingParameterCollection pl =
208                                 new BindingParameterCollection ();
209                         foreach (object o in parameters)
210                                 pl.Add (o);
211                         return BuildChannelListener<TChannel> (
212                                 listenUriBaseAddress, listenUriRelativeAddress, pl);
213                 }
214
215                 public virtual IChannelListener<TChannel>
216                         BuildChannelListener<TChannel> (
217                         Uri listenUriBaseAddress,
218                         string listenUriRelativeAddress,
219                         BindingParameterCollection parameters)
220                         where TChannel : class, IChannel
221                 {
222                         return BuildChannelListener<TChannel> (
223                                 listenUriBaseAddress,
224                                 listenUriRelativeAddress,
225                                 ListenUriMode.Explicit,
226                                 parameters);
227                 }
228
229                 public virtual IChannelListener<TChannel>
230                         BuildChannelListener<TChannel> (
231                         params object [] parameters)
232                         where TChannel : class, IChannel
233                 {
234                         BindingParameterCollection pl =
235                                 new BindingParameterCollection ();
236                         foreach (object o in parameters)
237                                 pl.Add (o);
238                         return BuildChannelListener<TChannel> (pl);
239                 }
240
241                 public virtual IChannelListener<TChannel>
242                         BuildChannelListener<TChannel> (
243                         BindingParameterCollection parameters)
244                         where TChannel : class, IChannel
245                 {
246                         if (parameters == null)
247                                 throw new ArgumentNullException ("parameters");
248                         return CreateContext (parameters).BuildInnerChannelListener<TChannel> ();
249                 }
250 #endif
251
252                 public bool CanBuildChannelFactory<TChannel> (
253                         params object [] parameters)
254                 {
255                         BindingParameterCollection pl =
256                                 new BindingParameterCollection ();
257                         foreach (object o in parameters)
258                                 pl.Add (o);
259                         return CanBuildChannelFactory<TChannel> (pl);
260                 }
261
262                 public virtual bool CanBuildChannelFactory<TChannel> (
263                         BindingParameterCollection parameters)
264                 {
265                         if (parameters == null)
266                                 throw new ArgumentNullException ("parameters");
267                         return CreateContext (parameters).CanBuildInnerChannelFactory<TChannel> ();
268                 }
269
270 #if !MOBILE
271                 public bool CanBuildChannelListener<TChannel> (
272                         params object [] parameters)
273                         where TChannel : class, IChannel
274                 {
275                         BindingParameterCollection pl =
276                                 new BindingParameterCollection ();
277                         foreach (object o in parameters)
278                                 pl.Add (o);
279                         return CanBuildChannelListener<TChannel> (pl);
280                 }
281
282                 public virtual bool CanBuildChannelListener<TChannel> (
283                         BindingParameterCollection parameters)
284                         where TChannel : class, IChannel
285                 {
286                         if (parameters == null)
287                                 throw new ArgumentNullException ("parameters");
288                         return CreateContext (parameters).CanBuildInnerChannelListener<TChannel> ();
289                 }
290 #endif
291
292                 public abstract BindingElementCollection CreateBindingElements ();
293
294                 public T GetProperty<T> (BindingParameterCollection parameters)
295                         where T : class
296                 {
297                         if (parameters == null)
298                                 throw new ArgumentNullException ("parameters");
299                         return CreateContext (parameters).GetInnerProperty<T> ();
300                 }
301
302                 private void Initialize ()
303                 {
304                         IDefaultCommunicationTimeouts t =
305                                 DefaultCommunicationTimeouts.Instance;
306                         open_timeout = t.OpenTimeout;
307                         close_timeout = t.CloseTimeout;
308                         receive_timeout = t.ReceiveTimeout;
309                         send_timeout = t.SendTimeout;
310                 }
311         }
312 }