2 // HttpTransportBindingElement.cs
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
;
31 using System
.Net
.Security
;
32 using System
.ServiceModel
.Channels
;
33 using System
.ServiceModel
.Description
;
35 namespace System
.ServiceModel
.Channels
38 public class HttpTransportBindingElement
: TransportBindingElement
,
39 IPolicyExportExtension
, IWsdlExportExtension
41 bool allow_cookies
, bypass_proxy_on_local
,
43 bool use_default_proxy
= true, keep_alive_enabled
= true;
44 int max_buffer_size
= 0x10000;
45 HostNameComparisonMode host_cmp_mode
;
47 string realm
= String
.Empty
;
48 TransferMode transfer_mode
;
49 IDefaultCommunicationTimeouts timeouts
;
51 AuthenticationSchemes auth_scheme
=
52 AuthenticationSchemes
.Anonymous
;
53 AuthenticationSchemes proxy_auth_scheme
=
54 AuthenticationSchemes
.Anonymous
;
56 // If you add fields, do not forget them in copy constructor.
58 public HttpTransportBindingElement ()
62 protected HttpTransportBindingElement (
63 HttpTransportBindingElement other
)
66 allow_cookies
= other
.allow_cookies
;
67 bypass_proxy_on_local
= other
.bypass_proxy_on_local
;
68 unsafe_ntlm_auth
= other
.unsafe_ntlm_auth
;
69 use_default_proxy
= other
.use_default_proxy
;
70 keep_alive_enabled
= other
.keep_alive_enabled
;
71 max_buffer_size
= other
.max_buffer_size
;
72 host_cmp_mode
= other
.host_cmp_mode
;
73 proxy_address
= other
.proxy_address
;
75 transfer_mode
= other
.transfer_mode
;
76 // FIXME: it does not look safe
77 timeouts
= other
.timeouts
;
79 auth_scheme
= other
.auth_scheme
;
80 proxy_auth_scheme
= other
.proxy_auth_scheme
;
85 public AuthenticationSchemes AuthenticationScheme
{
86 get { return auth_scheme; }
87 set { auth_scheme = value; }
90 public AuthenticationSchemes ProxyAuthenticationScheme
{
91 get { return proxy_auth_scheme; }
92 set { proxy_auth_scheme = value; }
96 public bool AllowCookies
{
97 get { return allow_cookies; }
98 set { allow_cookies = value; }
101 public bool BypassProxyOnLocal
{
102 get { return bypass_proxy_on_local; }
103 set { bypass_proxy_on_local = value; }
106 public HostNameComparisonMode HostNameComparisonMode
{
107 get { return host_cmp_mode; }
108 set { host_cmp_mode = value; }
111 public bool KeepAliveEnabled
{
112 get { return keep_alive_enabled; }
113 set { keep_alive_enabled = value; }
116 public int MaxBufferSize
{
117 get { return max_buffer_size; }
118 set { max_buffer_size = value; }
121 public Uri ProxyAddress
{
122 get { return proxy_address; }
123 set { proxy_address = value; }
126 public string Realm
{
127 get { return realm; }
128 set { realm = value; }
131 public override string Scheme
{
132 get { return Uri.UriSchemeHttp; }
135 public TransferMode TransferMode
{
136 get { return transfer_mode; }
137 set { transfer_mode = value; }
140 public bool UnsafeConnectionNtlmAuthentication
{
141 get { return unsafe_ntlm_auth; }
142 set { unsafe_ntlm_auth = value; }
145 public bool UseDefaultWebProxy
{
146 get { return use_default_proxy; }
147 set { use_default_proxy = value; }
150 public override bool CanBuildChannelFactory
<TChannel
> (
151 BindingContext context
)
153 return typeof (TChannel
) == typeof (IRequestChannel
);
157 public override bool CanBuildChannelListener
<TChannel
> (
158 BindingContext context
)
160 return typeof (TChannel
) == typeof (IReplyChannel
);
164 public override IChannelFactory
<TChannel
> BuildChannelFactory
<TChannel
> (
165 BindingContext context
)
167 // remaining contexts are ignored ... e.g. such binding
168 // element that always causes an error is ignored.
169 return new HttpChannelFactory
<TChannel
> (this, context
);
173 internal static object ListenerBuildLock
= new object ();
175 public override IChannelListener
<TChannel
> BuildChannelListener
<TChannel
> (
176 BindingContext context
)
178 // remaining contexts are ignored ... e.g. such binding
179 // element that always causes an error is ignored.
180 if (ServiceHostingEnvironment
.InAspNet
)
181 return new AspNetChannelListener
<TChannel
> (this, context
);
183 return new HttpSimpleChannelListener
<TChannel
> (this, context
);
187 public override BindingElement
Clone ()
189 return new HttpTransportBindingElement (this);
192 public override T GetProperty
<T
> (BindingContext context
)
194 // http://blogs.msdn.com/drnick/archive/2007/04/10/interfaces-for-getproperty-part-1.aspx
196 if (typeof (T
) == typeof (ISecurityCapabilities
))
197 return (T
) (object) new HttpBindingProperties (this);
198 if (typeof (T
) == typeof (IBindingDeliveryCapabilities
))
199 return (T
) (object) new HttpBindingProperties (this);
201 if (typeof (T
) == typeof (TransferMode
))
202 return (T
) (object) TransferMode
;
203 return base.GetProperty
<T
> (context
);
208 void IPolicyExportExtension
.ExportPolicy (
209 MetadataExporter exporter
,
210 PolicyConversionContext context
)
212 throw new NotImplementedException ();
216 void IWsdlExportExtension
.ExportContract (WsdlExporter exporter
,
217 WsdlContractConversionContext context
)
219 throw new NotImplementedException ();
223 void IWsdlExportExtension
.ExportEndpoint (WsdlExporter exporter
,
224 WsdlEndpointConversionContext context
)
226 throw new NotImplementedException ();
232 class HttpBindingProperties
: ISecurityCapabilities
, IBindingDeliveryCapabilities
234 HttpTransportBindingElement source
;
236 public HttpBindingProperties (HttpTransportBindingElement source
)
238 this.source
= source
;
241 public bool AssuresOrderedDelivery
{
242 get { return false; }
245 public bool QueuedDelivery
{
246 get { return false; }
249 public virtual ProtectionLevel SupportedRequestProtectionLevel
{
250 get { return ProtectionLevel.None; }
253 public virtual ProtectionLevel SupportedResponseProtectionLevel
{
254 get { return ProtectionLevel.None; }
257 public virtual bool SupportsClientAuthentication
{
258 get { return source.AuthenticationScheme != AuthenticationSchemes.Anonymous; }
261 public virtual bool SupportsServerAuthentication
{
263 switch (source
.AuthenticationScheme
) {
264 case AuthenticationSchemes
.Negotiate
:
272 public virtual bool SupportsClientWindowsIdentity
{
274 switch (source
.AuthenticationScheme
) {
275 case AuthenticationSchemes
.Basic
:
276 case AuthenticationSchemes
.Digest
: // hmm... why? but they return true on .NET
277 case AuthenticationSchemes
.Negotiate
:
278 case AuthenticationSchemes
.Ntlm
: