[WCF]: BasicHttpBinding API changes for .NET 4.5.

BasicHttpBinding received a few API cleanups and refactorings
in .NET 4.5:

* There is a new abstract HttpBindingBase class and most of
  BasicHttpBinding's API has been moved into this new class.

* There is a new BasicHttpsBinding.

* BasicHttpBinding / BasicHttpsBinding now only contain the APIs
  which are specific to http / https, the rest now lives in the
  new abstract HttpBindingBase.

* Similarly, there's now also HttpBindingBaseElement for the
  configuration.

* There is a new BasicHttpsSecurityMode enum, which only contains
  'Transport' and 'TransportWithMessageCredential', so you can't
  accidentally use an insecure transport.
This commit is contained in:
Martin Baulig committed 2012-11-27 01:46:47 +01:00
1 parent 831ce5fccc
commit 8e4dc61cc2
15 files changed
+1237 -1

No files matched your search

@@ -182,7 +182,8 @@
<Compile Include="System.ServiceModel\AddressAccessDeniedException.cs" />
<Compile Include="System.ServiceModel\AddressAlreadyInUseException.cs" />
<Compile Include="System.ServiceModel\AllEnums.cs" />
<Compile Include="System.ServiceModel\BasicHttpBinding.cs" />
<Compile Include="System.ServiceModel\HttpBindingBase.cs" />
<Compile Include="System.ServiceModel\BasicHttpBinding_4_5.cs" />
<Compile Include="System.ServiceModel\BasicHttpMessageSecurity.cs" />
<Compile Include="System.ServiceModel\BasicHttpSecurity.cs" />
<Compile Include="System.ServiceModel\CallbackBehaviorAttribute.cs" />
@@ -1,6 +1,11 @@
//
// BasicHttpBindingElement.cs
//
// See BasicHttpBindingElement_4_5.cs and HttpBindingBaseElement.cs
// for the .NET 4.5 version of this class, where most of the code has
// been moved into the new abstract HttpBindingBaseElement class.
//
//
// Author:
// Atsushi Enomoto <[email protected]>
//
@@ -26,6 +31,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if !NET_4_5
using System;
using System.Collections;
using System.Collections.Generic;
@@ -250,3 +256,4 @@ namespace System.ServiceModel.Configuration
}
}
#endif
@@ -0,0 +1,123 @@
//
// BasicHttpBindingElement_4_5.cs
//
// Authors:
// Atsushi Enomoto <[email protected]>
// Martin Baulig <[email protected]>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
// Copyright (c) 2012 Xamarin Inc. (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Configuration;
using System.Net;
using System.Net.Security;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using System.Security.Principal;
using System.IdentityModel.Claims;
using System.IdentityModel.Policy;
using System.IdentityModel.Tokens;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Diagnostics;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.MsmqIntegration;
using System.ServiceModel.PeerResolvers;
using System.ServiceModel.Security;
using System.Runtime.Serialization;
using System.Text;
using System.Xml;
namespace System.ServiceModel.Configuration
{
public class BasicHttpBindingElement
: HttpBindingBaseElement, IBindingConfigurationElement
{
ConfigurationPropertyCollection _properties;
public BasicHttpBindingElement ()
{
}
public BasicHttpBindingElement (string name) : base (name) { }
protected override Type BindingElementType {
get { return typeof (BasicHttpBinding); }
}
// Properties
[ConfigurationProperty ("messageEncoding",
DefaultValue = "Text",
Options = ConfigurationPropertyOptions.None)]
public WSMessageEncoding MessageEncoding {
get { return (WSMessageEncoding) this ["messageEncoding"]; }
set { this ["messageEncoding"] = value; }
}
protected override ConfigurationPropertyCollection Properties {
get {
if (_properties == null) {
_properties = base.Properties;
_properties.Add (new ConfigurationProperty ("messageEncoding", typeof (WSMessageEncoding), "Text", null, null, ConfigurationPropertyOptions.None));
_properties.Add (new ConfigurationProperty ("security", typeof (BasicHttpSecurityElement), null, null, null, ConfigurationPropertyOptions.None));
}
return _properties;
}
}
[ConfigurationProperty ("security",
Options = ConfigurationPropertyOptions.None)]
public BasicHttpSecurityElement Security {
get { return (BasicHttpSecurityElement) this ["security"]; }
}
protected override void OnApplyConfiguration (Binding binding)
{
base.OnApplyConfiguration (binding);
BasicHttpBinding basicHttpBinding = (BasicHttpBinding) binding;
basicHttpBinding.MessageEncoding = MessageEncoding;
basicHttpBinding.Security.Mode = Security.Mode;
Security.Transport.ApplyConfiguration (basicHttpBinding.Security.Transport);
}
protected internal override void InitializeFrom (Binding binding)
{
BasicHttpBinding b = (BasicHttpBinding) binding;
base.InitializeFrom (binding);
MessageEncoding = b.MessageEncoding;
Security.Mode = b.Security.Mode;
Security.Transport.ApplyConfiguration (b.Security.Transport);
}
}
}
@@ -0,0 +1,62 @@
//
// BasicHttpsBindingCollectionElement.cs
//
// Author:
// Martin Baulig <[email protected]>
//
// Copyright (c) 2012 Xamarin Inc. (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Configuration;
using System.Net;
using System.Net.Security;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using System.Security.Principal;
using System.IdentityModel.Claims;
using System.IdentityModel.Policy;
using System.IdentityModel.Tokens;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Diagnostics;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.MsmqIntegration;
using System.ServiceModel.PeerResolvers;
using System.ServiceModel.Security;
using System.Runtime.Serialization;
using System.Text;
using System.Xml;
namespace System.ServiceModel.Configuration
{
public partial class BasicHttpsBindingCollectionElement
: StandardBindingCollectionElement<BasicHttpsBinding, BasicHttpsBindingElement>
{
}
}
@@ -0,0 +1,123 @@
//
// BasicHttpsBindingElement.cs
//
// Authors:
// Atsushi Enomoto <[email protected]>
// Martin Baulig <[email protected]>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
// Copyright (c) 2012 Xamarin Inc. (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Configuration;
using System.Net;
using System.Net.Security;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using System.Security.Principal;
using System.IdentityModel.Claims;
using System.IdentityModel.Policy;
using System.IdentityModel.Tokens;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Diagnostics;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.MsmqIntegration;
using System.ServiceModel.PeerResolvers;
using System.ServiceModel.Security;
using System.Runtime.Serialization;
using System.Text;
using System.Xml;
namespace System.ServiceModel.Configuration
{
public class BasicHttpsBindingElement
: HttpBindingBaseElement, IBindingConfigurationElement
{
ConfigurationPropertyCollection _properties;
public BasicHttpsBindingElement ()
{
}
public BasicHttpsBindingElement (string name) : base (name) { }
protected override Type BindingElementType {
get { return typeof (BasicHttpsBinding); }
}
// Properties
[ConfigurationProperty ("messageEncoding",
DefaultValue = "Text",
Options = ConfigurationPropertyOptions.None)]
public WSMessageEncoding MessageEncoding {
get { return (WSMessageEncoding) this ["messageEncoding"]; }
set { this ["messageEncoding"] = value; }
}
protected override ConfigurationPropertyCollection Properties {
get {
if (_properties == null) {
_properties = base.Properties;
_properties.Add (new ConfigurationProperty ("messageEncoding", typeof (WSMessageEncoding), "Text", null, null, ConfigurationPropertyOptions.None));
_properties.Add (new ConfigurationProperty ("security", typeof (BasicHttpsSecurityElement), null, null, null, ConfigurationPropertyOptions.None));
}
return _properties;
}
}
[ConfigurationProperty ("security",
Options = ConfigurationPropertyOptions.None)]
public BasicHttpsSecurityElement Security {
get { return (BasicHttpsSecurityElement) this ["security"]; }
}
protected override void OnApplyConfiguration (Binding binding)
{
base.OnApplyConfiguration (binding);
BasicHttpsBinding basicHttpsBinding = (BasicHttpsBinding) binding;
basicHttpsBinding.MessageEncoding = MessageEncoding;
basicHttpsBinding.Security.Mode = Security.Mode;
Security.Transport.ApplyConfiguration (basicHttpsBinding.Security.Transport);
}
protected internal override void InitializeFrom (Binding binding)
{
BasicHttpsBinding b = (BasicHttpsBinding) binding;
base.InitializeFrom (binding);
MessageEncoding = b.MessageEncoding;
Security.Mode = b.Security.Mode;
Security.Transport.ApplyConfiguration (b.Security.Transport);
}
}
}
@@ -0,0 +1,91 @@
//
// BasicHttpsSecurityElement.cs
//
// Authors:
// Atsushi Enomoto <[email protected]>
// Martin Baulig <[email protected]>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
// Copyright (c) 2012 Xamarin Inc. (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Configuration;
using System.Net;
using System.Net.Security;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using System.Security.Principal;
using System.IdentityModel.Claims;
using System.IdentityModel.Policy;
using System.IdentityModel.Tokens;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Diagnostics;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.MsmqIntegration;
using System.ServiceModel.PeerResolvers;
using System.ServiceModel.Security;
using System.Runtime.Serialization;
using System.Text;
using System.Xml;
namespace System.ServiceModel.Configuration
{
public sealed class BasicHttpsSecurityElement
: ConfigurationElement
{
// Properties
[ConfigurationProperty ("message",
Options = ConfigurationPropertyOptions.None)]
public BasicHttpMessageSecurityElement Message {
get { return (BasicHttpMessageSecurityElement) base ["message"]; }
}
[ConfigurationProperty ("mode",
DefaultValue = "None",
Options = ConfigurationPropertyOptions.None)]
public BasicHttpsSecurityMode Mode {
get { return (BasicHttpsSecurityMode) base ["mode"]; }
set { base ["mode"] = value; }
}
protected override ConfigurationPropertyCollection Properties {
get { return base.Properties; }
}
[ConfigurationProperty ("transport",
Options = ConfigurationPropertyOptions.None)]
public HttpTransportSecurityElement Transport {
get { return (HttpTransportSecurityElement) base ["transport"]; }
}
}
}
@@ -67,6 +67,14 @@ namespace System.ServiceModel.Configuration
get { return (BasicHttpBindingCollectionElement) this ["basicHttpBinding"]; }
}
#if NET_4_5
[ConfigurationProperty ("basicHttpsBinding",
Options = ConfigurationPropertyOptions.None)]
public BasicHttpsBindingCollectionElement BasicHttpsBinding {
get { return (BasicHttpsBindingCollectionElement) this ["basicHttpsBinding"]; }
}
#endif
[MonoTODO ("Not Implemented")]
public List<BindingCollectionElement> BindingCollections {
get { throw new NotImplementedException (); }
@@ -0,0 +1,232 @@
//
// HttpBindingBaseElement.cs
//
// This is a .NET 4.5 addition and contains most of the code from
// BasicHttpBindingElement.
//
//
// Authors:
// Atsushi Enomoto <[email protected]>
// Martin Baulig <[email protected]>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
// Copyright (c) 2012 Xamarin Inc. (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Configuration;
using System.Net;
using System.Net.Security;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using System.Security.Principal;
using System.IdentityModel.Claims;
using System.IdentityModel.Policy;
using System.IdentityModel.Tokens;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Diagnostics;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.MsmqIntegration;
using System.ServiceModel.PeerResolvers;
using System.ServiceModel.Security;
using System.Runtime.Serialization;
using System.Text;
using System.Xml;
namespace System.ServiceModel.Configuration
{
public abstract class HttpBindingBaseElement
: StandardBindingElement, IBindingConfigurationElement
{
ConfigurationPropertyCollection _properties;
public HttpBindingBaseElement ()
{
}
public HttpBindingBaseElement (string name) : base (name) { }
// Properties
[ConfigurationProperty ("allowCookies",
DefaultValue = false,
Options = ConfigurationPropertyOptions.None)]
public bool AllowCookies {
get { return (bool) this ["allowCookies"]; }
set { this ["allowCookies"] = value; }
}
[ConfigurationProperty ("bypassProxyOnLocal",
DefaultValue = false,
Options = ConfigurationPropertyOptions.None)]
public bool BypassProxyOnLocal {
get { return (bool) this ["bypassProxyOnLocal"]; }
set { this ["bypassProxyOnLocal"] = value; }
}
[ConfigurationProperty ("hostNameComparisonMode",
DefaultValue = "StrongWildcard",
Options = ConfigurationPropertyOptions.None)]
public HostNameComparisonMode HostNameComparisonMode {
get { return (HostNameComparisonMode) this ["hostNameComparisonMode"]; }
set { this ["hostNameComparisonMode"] = value; }
}
[LongValidator ( MinValue = 0,
MaxValue = 9223372036854775807,
ExcludeRange = false)]
[ConfigurationProperty ("maxBufferPoolSize",
DefaultValue = "524288",
Options = ConfigurationPropertyOptions.None)]
public long MaxBufferPoolSize {
get { return (long) this ["maxBufferPoolSize"]; }
set { this ["maxBufferPoolSize"] = value; }
}
[IntegerValidator ( MinValue = 1,
MaxValue = int.MaxValue,
ExcludeRange = false)]
[ConfigurationProperty ("maxBufferSize",
DefaultValue = "65536",
Options = ConfigurationPropertyOptions.None)]
public int MaxBufferSize {
get { return (int) this ["maxBufferSize"]; }
set { this ["maxBufferSize"] = value; }
}
[LongValidator ( MinValue = 1,
MaxValue = 9223372036854775807,
ExcludeRange = false)]
[ConfigurationProperty ("maxReceivedMessageSize",
DefaultValue = "65536",
Options = ConfigurationPropertyOptions.None)]
public long MaxReceivedMessageSize {
get { return (long) this ["maxReceivedMessageSize"]; }
set { this ["maxReceivedMessageSize"] = value; }
}
protected override ConfigurationPropertyCollection Properties {
get {
if (_properties == null) {
_properties = base.Properties;
_properties.Add (new ConfigurationProperty ("allowCookies", typeof (bool), "false", null, null, ConfigurationPropertyOptions.None));
_properties.Add (new ConfigurationProperty ("bypassProxyOnLocal", typeof (bool), "false", null, null, ConfigurationPropertyOptions.None));
_properties.Add (new ConfigurationProperty ("hostNameComparisonMode", typeof (HostNameComparisonMode), "StrongWildcard", null, null, ConfigurationPropertyOptions.None));
_properties.Add (new ConfigurationProperty ("maxBufferPoolSize", typeof (long), "524288", null, new LongValidator (0, 9223372036854775807, false), ConfigurationPropertyOptions.None));
_properties.Add (new ConfigurationProperty ("maxBufferSize", typeof (int), "65536", null, new IntegerValidator (1, int.MaxValue, false), ConfigurationPropertyOptions.None));
_properties.Add (new ConfigurationProperty ("maxReceivedMessageSize", typeof (long), "65536", null, new LongValidator (1, 9223372036854775807, false), ConfigurationPropertyOptions.None));
_properties.Add (new ConfigurationProperty ("proxyAddress", typeof (Uri), null, new UriTypeConverter (), null, ConfigurationPropertyOptions.None));
_properties.Add (new ConfigurationProperty ("readerQuotas", typeof (XmlDictionaryReaderQuotasElement), null, null, null, ConfigurationPropertyOptions.None));
_properties.Add (new ConfigurationProperty ("textEncoding", typeof (Encoding), "utf-8", EncodingConverter.Instance, null, ConfigurationPropertyOptions.None));
_properties.Add (new ConfigurationProperty ("transferMode", typeof (TransferMode), "Buffered", null, null, ConfigurationPropertyOptions.None));
_properties.Add (new ConfigurationProperty ("useDefaultWebProxy", typeof (bool), "true", new BooleanConverter (), null, ConfigurationPropertyOptions.None));
}
return _properties;
}
}
[ConfigurationProperty ("proxyAddress",
DefaultValue = null,
Options = ConfigurationPropertyOptions.None)]
public Uri ProxyAddress {
get { return (Uri) this ["proxyAddress"]; }
set { this ["proxyAddress"] = value; }
}
[ConfigurationProperty ("readerQuotas",
Options = ConfigurationPropertyOptions.None)]
public XmlDictionaryReaderQuotasElement ReaderQuotas {
get { return (XmlDictionaryReaderQuotasElement) this ["readerQuotas"]; }
}
[TypeConverter (typeof (EncodingConverter))]
[ConfigurationProperty ("textEncoding",
DefaultValue = "utf-8",
Options = ConfigurationPropertyOptions.None)]
public Encoding TextEncoding {
get { return (Encoding) this ["textEncoding"]; }
set { this ["textEncoding"] = value; }
}
[ConfigurationProperty ("transferMode",
DefaultValue = "Buffered",
Options = ConfigurationPropertyOptions.None)]
public TransferMode TransferMode {
get { return (TransferMode) this ["transferMode"]; }
set { this ["transferMode"] = value; }
}
[ConfigurationProperty ("useDefaultWebProxy",
DefaultValue = true,
Options = ConfigurationPropertyOptions.None)]
public bool UseDefaultWebProxy {
get { return (bool) this ["useDefaultWebProxy"]; }
set { this ["useDefaultWebProxy"] = value; }
}
protected override void OnApplyConfiguration (Binding binding)
{
HttpBindingBase basicHttpBinding = (HttpBindingBase) binding;
basicHttpBinding.AllowCookies = AllowCookies;
basicHttpBinding.BypassProxyOnLocal = BypassProxyOnLocal;
basicHttpBinding.HostNameComparisonMode = HostNameComparisonMode;
basicHttpBinding.MaxBufferPoolSize = MaxBufferPoolSize;
basicHttpBinding.MaxBufferSize = MaxBufferSize;
basicHttpBinding.MaxReceivedMessageSize = MaxReceivedMessageSize;
basicHttpBinding.ProxyAddress = ProxyAddress;
ReaderQuotas.ApplyConfiguration (basicHttpBinding.ReaderQuotas);
basicHttpBinding.TextEncoding = TextEncoding;
basicHttpBinding.TransferMode = TransferMode;
basicHttpBinding.UseDefaultWebProxy = UseDefaultWebProxy;
}
protected internal override void InitializeFrom (Binding binding)
{
HttpBindingBase b = (HttpBindingBase) binding;
base.InitializeFrom (binding);
AllowCookies = b.AllowCookies;
BypassProxyOnLocal = b.BypassProxyOnLocal;
HostNameComparisonMode = b.HostNameComparisonMode;
MaxBufferPoolSize = b.MaxBufferPoolSize;
MaxBufferSize = b.MaxBufferSize;
MaxReceivedMessageSize = b.MaxReceivedMessageSize;
ProxyAddress = b.ProxyAddress;
ReaderQuotas.ApplyConfiguration (b.ReaderQuotas);
TextEncoding = b.TextEncoding;
TransferMode = b.TransferMode;
UseDefaultWebProxy = b.UseDefaultWebProxy;
}
}
}
@@ -74,6 +74,14 @@ namespace System.ServiceModel
TransportCredentialOnly,
}
#if NET_4_5
public enum BasicHttpsSecurityMode
{
Transport,
TransportWithMessageCredential
}
#endif
public enum CommunicationState
{
Created,
@@ -1,6 +1,9 @@
//
// BasicHttpBinding.cs
//
// See BasicHttpBinding_4_5.cs and HttpBindingBase.cs for the .NET 4.5
// version of this class.
//
// Author:
// Atsushi Enomoto <[email protected]>
//
@@ -26,6 +29,7 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if !NET_4_5
using System;
using System.Collections.Generic;
using System.Net;
@@ -310,3 +314,4 @@ namespace System.ServiceModel
}
}
}
#endif
@@ -0,0 +1,196 @@
//
// BasicHttpBinding_4_5.cs
//
// Authors:
// Atsushi Enomoto <[email protected]>
// Martin Baulig <[email protected]>
//
// Copyright (C) 2005-2006 Novell, Inc. http://www.novell.com
// Copyright 2011-2012 Xamarin Inc (http://www.xamarin.com).
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Security;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Text;
using System.Xml;
using System.ServiceModel.Configuration;
namespace System.ServiceModel
{
public class BasicHttpBinding : HttpBindingBase,
IBindingRuntimePreferences
{
WSMessageEncoding message_encoding = WSMessageEncoding.Text;
BasicHttpSecurity security;
public BasicHttpBinding ()
: this (BasicHttpSecurityMode.None)
{
}
public BasicHttpBinding (string configurationName)
: this ()
{
BindingsSection bindingsSection = ConfigUtil.BindingsSection;
BasicHttpBindingElement el =
bindingsSection.BasicHttpBinding.Bindings [configurationName];
el.ApplyConfiguration (this);
}
public BasicHttpBinding (
BasicHttpSecurityMode securityMode)
{
security = new BasicHttpSecurity (securityMode);
}
public WSMessageEncoding MessageEncoding {
get { return message_encoding; }
set { message_encoding = value; }
}
public override string Scheme {
get {
switch (Security.Mode) {
case BasicHttpSecurityMode.Transport:
case BasicHttpSecurityMode.TransportWithMessageCredential:
return Uri.UriSchemeHttps;
default:
return Uri.UriSchemeHttp;
}
}
}
public BasicHttpSecurity Security {
get { return security; }
}
public override BindingElementCollection
CreateBindingElements ()
{
var list = new List<BindingElement> ();
var security = CreateSecurityBindingElement ();
if (security != null)
list.Add (security);
list.Add (BuildMessageEncodingBindingElement ());
list.Add (GetTransport ());
return new BindingElementCollection (list.ToArray ());
}
SecurityBindingElement CreateSecurityBindingElement ()
{
SecurityBindingElement element;
switch (Security.Mode) {
case BasicHttpSecurityMode.Message:
if (Security.Message.ClientCredentialType != BasicHttpMessageCredentialType.Certificate)
throw new InvalidOperationException ("When Message security is enabled in a BasicHttpBinding, the message security credential type must be BasicHttpMessageCredentialType.Certificate.");
element = SecurityBindingElement.CreateMutualCertificateBindingElement (
MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10);
break;
case BasicHttpSecurityMode.TransportWithMessageCredential:
if (Security.Message.ClientCredentialType != BasicHttpMessageCredentialType.Certificate)
// FIXME: pass proper security token parameters.
element = SecurityBindingElement.CreateCertificateOverTransportBindingElement ();
else
element = new AsymmetricSecurityBindingElement ();
break;
default:
return null;
}
element.SetKeyDerivation (false);
element.SecurityHeaderLayout = SecurityHeaderLayout.Lax;
return element;
}
MessageEncodingBindingElement BuildMessageEncodingBindingElement ()
{
if (MessageEncoding == WSMessageEncoding.Text) {
TextMessageEncodingBindingElement tm = new TextMessageEncodingBindingElement (
MessageVersion.CreateVersion (EnvelopeVersion, AddressingVersion.None), TextEncoding);
ReaderQuotas.CopyTo (tm.ReaderQuotas);
return tm;
} else {
return new MtomMessageEncodingBindingElement (
MessageVersion.CreateVersion (EnvelopeVersion, AddressingVersion.None), TextEncoding);
}
}
TransportBindingElement GetTransport ()
{
HttpTransportBindingElement h;
switch (Security.Mode) {
case BasicHttpSecurityMode.Transport:
case BasicHttpSecurityMode.TransportWithMessageCredential:
h = new HttpsTransportBindingElement ();
break;
default:
h = new HttpTransportBindingElement ();
break;
}
h.AllowCookies = AllowCookies;
h.BypassProxyOnLocal = BypassProxyOnLocal;
h.HostNameComparisonMode = HostNameComparisonMode;
h.MaxBufferPoolSize = MaxBufferPoolSize;
h.MaxBufferSize = MaxBufferSize;
h.MaxReceivedMessageSize = MaxReceivedMessageSize;
h.ProxyAddress = ProxyAddress;
h.UseDefaultWebProxy = UseDefaultWebProxy;
h.TransferMode = TransferMode;
h.ExtendedProtectionPolicy = Security.Transport.ExtendedProtectionPolicy;
switch (Security.Transport.ClientCredentialType) {
case HttpClientCredentialType.Basic:
h.AuthenticationScheme = AuthenticationSchemes.Basic;
break;
case HttpClientCredentialType.Ntlm:
h.AuthenticationScheme = AuthenticationSchemes.Ntlm;
break;
case HttpClientCredentialType.Windows:
h.AuthenticationScheme = AuthenticationSchemes.Negotiate;
break;
case HttpClientCredentialType.Digest:
h.AuthenticationScheme = AuthenticationSchemes.Digest;
break;
case HttpClientCredentialType.Certificate:
switch (Security.Mode) {
case BasicHttpSecurityMode.Transport:
(h as HttpsTransportBindingElement).RequireClientCertificate = true;
break;
case BasicHttpSecurityMode.TransportCredentialOnly:
throw new InvalidOperationException ("Certificate-based client authentication is not supported by 'TransportCredentialOnly' mode.");
}
break;
}
return h;
}
}
}
@@ -0,0 +1,166 @@
//
// BasicHttpsBinding.cs
//
// Authors:
// Atsushi Enomoto <[email protected]>
// Martin Baulig <[email protected]>
//
// Copyright (C) 2005-2006 Novell, Inc. http://www.novell.com
// Copyright 2011-2012 Xamarin Inc (http://www.xamarin.com).
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Security;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Text;
using System.Xml;
using System.ServiceModel.Configuration;
namespace System.ServiceModel
{
public class BasicHttpsBinding : HttpBindingBase,
IBindingRuntimePreferences
{
WSMessageEncoding message_encoding = WSMessageEncoding.Text;
BasicHttpsSecurity security;
public BasicHttpsBinding ()
: this (BasicHttpsSecurityMode.Transport)
{
}
public BasicHttpsBinding (string configurationName)
: this ()
{
BindingsSection bindingsSection = ConfigUtil.BindingsSection;
BasicHttpsBindingElement el =
bindingsSection.BasicHttpsBinding.Bindings [configurationName];
el.ApplyConfiguration (this);
}
public BasicHttpsBinding (
BasicHttpsSecurityMode securityMode)
{
security = new BasicHttpsSecurity (securityMode);
}
public WSMessageEncoding MessageEncoding {
get { return message_encoding; }
set { message_encoding = value; }
}
public override string Scheme {
get { return Uri.UriSchemeHttps; }
}
public BasicHttpsSecurity Security {
get { return security; }
}
public override BindingElementCollection
CreateBindingElements ()
{
var list = new List<BindingElement> ();
var security = CreateSecurityBindingElement ();
if (security != null)
list.Add (security);
list.Add (BuildMessageEncodingBindingElement ());
list.Add (GetTransport ());
return new BindingElementCollection (list.ToArray ());
}
SecurityBindingElement CreateSecurityBindingElement ()
{
SecurityBindingElement element;
switch (Security.Mode) {
case BasicHttpsSecurityMode.TransportWithMessageCredential:
if (Security.Message.ClientCredentialType != BasicHttpMessageCredentialType.Certificate)
// FIXME: pass proper security token parameters.
element = SecurityBindingElement.CreateCertificateOverTransportBindingElement ();
else
element = new AsymmetricSecurityBindingElement ();
break;
default:
return null;
}
element.SetKeyDerivation (false);
element.SecurityHeaderLayout = SecurityHeaderLayout.Lax;
return element;
}
MessageEncodingBindingElement BuildMessageEncodingBindingElement ()
{
if (MessageEncoding == WSMessageEncoding.Text) {
TextMessageEncodingBindingElement tm = new TextMessageEncodingBindingElement (
MessageVersion.CreateVersion (EnvelopeVersion, AddressingVersion.None), TextEncoding);
ReaderQuotas.CopyTo (tm.ReaderQuotas);
return tm;
} else {
return new MtomMessageEncodingBindingElement (
MessageVersion.CreateVersion (EnvelopeVersion, AddressingVersion.None), TextEncoding);
}
}
TransportBindingElement GetTransport ()
{
HttpsTransportBindingElement h = new HttpsTransportBindingElement ();
h.AllowCookies = AllowCookies;
h.BypassProxyOnLocal = BypassProxyOnLocal;
h.HostNameComparisonMode = HostNameComparisonMode;
h.MaxBufferPoolSize = MaxBufferPoolSize;
h.MaxBufferSize = MaxBufferSize;
h.MaxReceivedMessageSize = MaxReceivedMessageSize;
h.ProxyAddress = ProxyAddress;
h.UseDefaultWebProxy = UseDefaultWebProxy;
h.TransferMode = TransferMode;
h.ExtendedProtectionPolicy = Security.Transport.ExtendedProtectionPolicy;
switch (Security.Transport.ClientCredentialType) {
case HttpClientCredentialType.Basic:
h.AuthenticationScheme = AuthenticationSchemes.Basic;
break;
case HttpClientCredentialType.Ntlm:
h.AuthenticationScheme = AuthenticationSchemes.Ntlm;
break;
case HttpClientCredentialType.Windows:
h.AuthenticationScheme = AuthenticationSchemes.Negotiate;
break;
case HttpClientCredentialType.Digest:
h.AuthenticationScheme = AuthenticationSchemes.Digest;
break;
case HttpClientCredentialType.Certificate:
h.RequireClientCertificate = true;
break;
}
return h;
}
}
}
@@ -0,0 +1,62 @@
//
// BasicHttpsSecurity.cs
//
// Authors:
// Atsushi Enomoto <[email protected]>
// Martin Baulig <[email protected]>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
// Copyright 2012 Xamarin Inc (http://www.xamarin.com).
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Net.Security;
using System.ServiceModel.Channels;
namespace System.ServiceModel
{
public sealed class BasicHttpsSecurity
{
internal BasicHttpsSecurity (BasicHttpsSecurityMode mode)
{
this.mode = mode;
this.message = new BasicHttpMessageSecurity ();
this.transport = new HttpTransportSecurity ();
}
BasicHttpMessageSecurity message;
BasicHttpsSecurityMode mode;
HttpTransportSecurity transport;
public BasicHttpMessageSecurity Message {
get { return message; }
}
public BasicHttpsSecurityMode Mode {
get { return mode; }
set { mode = value; }
}
public HttpTransportSecurity Transport {
get { return transport; }
}
}
}
@@ -0,0 +1,143 @@
//
// HttpBindingBase.cs
//
// Authors:
// Atsushi Enomoto <[email protected]>
// Martin Baulig <[email protected]>
//
// Copyright (C) 2005-2006 Novell, Inc. http://www.novell.com
// Copyright 2011-2012 Xamarin Inc (http://www.xamarin.com).
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Security;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Text;
using System.Xml;
using System.ServiceModel.Configuration;
namespace System.ServiceModel
{
public abstract class HttpBindingBase : Binding,
IBindingRuntimePreferences
{
bool allow_cookies, bypass_proxy_on_local;
HostNameComparisonMode host_name_comparison_mode
= HostNameComparisonMode.StrongWildcard;
long max_buffer_pool_size = 0x80000;
int max_buffer_size = 0x10000;
long max_recv_message_size = 0x10000;
Uri proxy_address;
XmlDictionaryReaderQuotas reader_quotas
= new XmlDictionaryReaderQuotas ();
EnvelopeVersion env_version = EnvelopeVersion.Soap11;
Encoding text_encoding = new UTF8Encoding ();
TransferMode transfer_mode
= TransferMode.Buffered;
bool use_default_web_proxy = true;
public bool AllowCookies {
get { return allow_cookies; }
set { allow_cookies = value; }
}
public bool BypassProxyOnLocal {
get { return bypass_proxy_on_local; }
set { bypass_proxy_on_local = value; }
}
public HostNameComparisonMode HostNameComparisonMode {
get { return host_name_comparison_mode; }
set { host_name_comparison_mode = value; }
}
public long MaxBufferPoolSize {
get { return max_buffer_pool_size; }
set {
if (value <= 0)
throw new ArgumentOutOfRangeException ();
max_buffer_pool_size = value;
}
}
public int MaxBufferSize {
get { return max_buffer_size; }
set {
if (value <= 0)
throw new ArgumentOutOfRangeException ();
max_buffer_size = value;
}
}
public long MaxReceivedMessageSize {
get { return max_recv_message_size; }
set {
if (value <= 0)
throw new ArgumentOutOfRangeException ();
max_recv_message_size = value;
}
}
public Uri ProxyAddress {
get { return proxy_address; }
set { proxy_address = value; }
}
public XmlDictionaryReaderQuotas ReaderQuotas {
get { return reader_quotas; }
set { reader_quotas = value; }
}
public override abstract string Scheme {
get;
}
public EnvelopeVersion EnvelopeVersion {
get { return env_version; }
}
public Encoding TextEncoding {
get { return text_encoding; }
set { text_encoding = value; }
}
public TransferMode TransferMode {
get { return transfer_mode; }
set { transfer_mode = value; }
}
public bool UseDefaultWebProxy {
get { return use_default_web_proxy; }
set { use_default_web_proxy = value; }
}
public override abstract BindingElementCollection CreateBindingElements ();
// explicit interface implementations
bool IBindingRuntimePreferences.ReceiveSynchronously {
get { return false; }
}
}
}
@@ -1 +1,10 @@
#include net_4_0_System.ServiceModel.dll.sources
System.ServiceModel/HttpBindingBase.cs
System.ServiceModel/BasicHttpBinding_4_5.cs
System.ServiceModel/BasicHttpsBinding.cs
System.ServiceModel/BasicHttpsSecurity.cs
System.ServiceModel.Configuration/BasicHttpBindingElement_4_5.cs
System.ServiceModel.Configuration/HttpBindingBaseElement.cs
System.ServiceModel.Configuration/BasicHttpsBindingElement.cs
System.ServiceModel.Configuration/BasicHttpsSecurityElement.cs
System.ServiceModel.Configuration/BasicHttpsBindingCollectionElement.cs