2009-06-11 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Channels / HttpTransportBindingElement.cs
1 //
2 // HttpTransportBindingElement.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.Net;
31 using System.Net.Security;
32 using System.ServiceModel.Channels;
33 using System.ServiceModel.Description;
34
35 namespace System.ServiceModel.Channels
36 {
37         [MonoTODO]
38         public class HttpTransportBindingElement : TransportBindingElement,
39                 IPolicyExportExtension, IWsdlExportExtension
40         {
41                 bool allow_cookies, bypass_proxy_on_local,
42                         unsafe_ntlm_auth;
43                 bool use_default_proxy = true, keep_alive_enabled = true;
44                 int max_buffer_size = 0x10000;
45                 AuthenticationSchemes auth_scheme =
46                         AuthenticationSchemes.Anonymous;
47                 AuthenticationSchemes proxy_auth_scheme =
48                         AuthenticationSchemes.Anonymous;
49                 HostNameComparisonMode host_cmp_mode;
50                 Uri proxy_address;
51                 string realm = String.Empty;
52                 TransferMode transfer_mode;
53                 IDefaultCommunicationTimeouts timeouts;
54                 // If you add fields, do not forget them in copy constructor.
55
56                 public HttpTransportBindingElement ()
57                 {
58                 }
59
60                 protected HttpTransportBindingElement (
61                         HttpTransportBindingElement other)
62                         : base (other)
63                 {
64                         allow_cookies = other.allow_cookies;
65                         bypass_proxy_on_local = other.bypass_proxy_on_local;
66                         unsafe_ntlm_auth = other.unsafe_ntlm_auth;
67                         use_default_proxy = other.use_default_proxy;
68                         keep_alive_enabled = other.keep_alive_enabled;
69                         max_buffer_size = other.max_buffer_size;
70                         auth_scheme = other.auth_scheme;
71                         proxy_auth_scheme = other.proxy_auth_scheme;
72                         host_cmp_mode = other.host_cmp_mode;
73                         proxy_address = other.proxy_address;
74                         realm = other.realm;
75                         transfer_mode = other.transfer_mode;
76                         // FIXME: it does not look safe
77                         timeouts = other.timeouts;
78                 }
79
80                 public bool AllowCookies {
81                         get { return allow_cookies; }
82                         set { allow_cookies = value; }
83                 }
84
85                 public AuthenticationSchemes AuthenticationScheme {
86                         get { return auth_scheme; }
87                         set { auth_scheme = value; }
88                 }
89
90                 public bool BypassProxyOnLocal {
91                         get { return bypass_proxy_on_local; }
92                         set { bypass_proxy_on_local = value; }
93                 }
94
95                 public HostNameComparisonMode HostNameComparisonMode {
96                         get { return host_cmp_mode; }
97                         set { host_cmp_mode = value; }
98                 }
99
100                 public bool KeepAliveEnabled {
101                         get { return keep_alive_enabled; }
102                         set { keep_alive_enabled = value; }
103                 }
104
105                 public int MaxBufferSize {
106                         get { return max_buffer_size; }
107                         set { max_buffer_size = value; }
108                 }
109
110                 public Uri ProxyAddress {
111                         get { return proxy_address; }
112                         set { proxy_address = value; }
113                 }
114
115                 public AuthenticationSchemes ProxyAuthenticationScheme {
116                         get { return proxy_auth_scheme; }
117                         set { proxy_auth_scheme = value; }
118                 }
119
120                 public string Realm {
121                         get { return realm; }
122                         set { realm = value; }
123                 }
124
125                 public override string Scheme {
126                         get { return Uri.UriSchemeHttp; }
127                 }
128
129                 public TransferMode TransferMode {
130                         get { return transfer_mode; }
131                         set { transfer_mode = value; }
132                 }
133
134                 public bool UnsafeConnectionNtlmAuthentication {
135                         get { return unsafe_ntlm_auth; }
136                         set { unsafe_ntlm_auth = value; }
137                 }
138
139                 public bool UseDefaultWebProxy {
140                         get { return use_default_proxy; }
141                         set { use_default_proxy = value; }
142                 }
143
144                 public override bool CanBuildChannelFactory<TChannel> (
145                         BindingContext context)
146                 {
147                         return typeof (TChannel) == typeof (IRequestChannel);
148                 }
149
150 #if !NET_2_1
151                 public override bool CanBuildChannelListener<TChannel> (
152                         BindingContext context)
153                 {
154                         return typeof (TChannel) == typeof (IReplyChannel);
155                 }
156 #endif
157
158                 public override IChannelFactory<TChannel> BuildChannelFactory<TChannel> (
159                         BindingContext context)
160                 {
161                         // remaining contexts are ignored ... e.g. such binding
162                         // element that always causes an error is ignored.
163                         return new HttpChannelFactory<TChannel> (this, context);
164                 }
165
166 #if !NET_2_1
167                 public override IChannelListener<TChannel> BuildChannelListener<TChannel> (
168                         BindingContext context)
169                 {
170                         // remaining contexts are ignored ... e.g. such binding
171                         // element that always causes an error is ignored.
172                         if (ServiceHostingEnvironment.InAspNet)
173                                 return new AspNetChannelListener<TChannel> (this, context);
174                         else
175                                 return new HttpSimpleChannelListener<TChannel> (this, context);
176                 }
177 #endif
178
179                 public override BindingElement Clone ()
180                 {
181                         return new HttpTransportBindingElement (this);
182                 }
183
184                 [MonoTODO]
185                 public override T GetProperty<T> (BindingContext context)
186                 {
187                         return base.GetProperty<T> (context);
188                 }
189
190 #if !NET_2_1
191                 [MonoTODO]
192                 void IPolicyExportExtension.ExportPolicy (
193                         MetadataExporter exporter,
194                         PolicyConversionContext context)
195                 {
196                         throw new NotImplementedException ();
197                 }
198
199                 [MonoTODO]
200                 void IWsdlExportExtension.ExportContract (WsdlExporter exporter,
201                         WsdlContractConversionContext context)
202                 {
203                         throw new NotImplementedException ();
204                 }
205
206                 [MonoTODO]
207                 void IWsdlExportExtension.ExportEndpoint (WsdlExporter exporter,
208                         WsdlEndpointConversionContext context)
209                 {
210                         throw new NotImplementedException ();
211                 }
212 #endif
213         }
214 }