Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,188 @@
//
// System.ServiceModel.AddressHeader.cs
//
// Authors:
// Duncan Mak (duncan@novell.com)
// Atsushi Enomoto (atsushi@ximian.com)
//
// Copyright (C) 2005,2010 Novell, Inc (http://www.novell.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.IO;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Xml;
using System.Xml.Schema;
namespace System.ServiceModel.Channels
{
public abstract class AddressHeader
{
protected AddressHeader () {}
public static AddressHeader CreateAddressHeader (object value)
{
return new DefaultAddressHeader (value);
}
public static AddressHeader CreateAddressHeader (object value, XmlObjectSerializer formatter)
{
return new DefaultAddressHeader (value, formatter);
}
public static AddressHeader CreateAddressHeader (string name, string ns, object value)
{
return new DefaultAddressHeader (name, ns, value);
}
public static AddressHeader CreateAddressHeader (string name, string ns, object value,
XmlObjectSerializer formatter)
{
if (formatter == null)
throw new ArgumentNullException ("formatter");
return new DefaultAddressHeader (name, ns, value, formatter);
}
public override bool Equals (object obj)
{
AddressHeader o = obj as AddressHeader;
if (o == null)
return false;
return o.Name == this.Name && o.Namespace == this.Namespace;
}
public virtual XmlDictionaryReader GetAddressHeaderReader ()
{
var sw = new StringWriter ();
var s = new XmlWriterSettings () { OmitXmlDeclaration = true };
var xw = XmlDictionaryWriter.CreateDictionaryWriter (XmlWriter.Create (sw, s));
WriteAddressHeader (xw);
xw.Close ();
return XmlDictionaryReader.CreateDictionaryReader (XmlReader.Create (new StringReader (sw.ToString ())));
}
public override int GetHashCode ()
{
return this.Name.GetHashCode () + this.Namespace.GetHashCode ();
}
public T GetValue<T> ()
{
return GetValue<T> (new DataContractSerializer (typeof (T)));
}
public T GetValue<T> (XmlObjectSerializer formatter)
{
return (T) formatter.ReadObject (GetAddressHeaderReader ());
}
protected abstract void OnWriteAddressHeaderContents (XmlDictionaryWriter writer);
protected virtual void OnWriteStartAddressHeader (XmlDictionaryWriter writer)
{
if (Name != null && Namespace != null)
writer.WriteStartElement (Name, Namespace);
}
public MessageHeader ToMessageHeader ()
{
throw new NotImplementedException ();
}
public void WriteAddressHeader (XmlDictionaryWriter writer)
{
if (writer == null)
throw new ArgumentNullException ("writer is null");
this.WriteStartAddressHeader (writer);
this.WriteAddressHeaderContents (writer);
if (Name != null && Namespace != null)
writer.WriteEndElement ();
}
public void WriteAddressHeader (XmlWriter writer)
{
this.WriteAddressHeader (XmlDictionaryWriter.CreateDictionaryWriter (writer));
}
public void WriteAddressHeaderContents (XmlDictionaryWriter writer)
{
this.OnWriteAddressHeaderContents (writer);
}
public void WriteStartAddressHeader (XmlDictionaryWriter writer)
{
this.OnWriteStartAddressHeader (writer);
}
public abstract string Name { get; }
public abstract string Namespace { get; }
internal class DefaultAddressHeader : AddressHeader
{
string name, ns;
XmlObjectSerializer formatter;
object value;
internal DefaultAddressHeader (object value)
: this (null, null, value) {}
internal DefaultAddressHeader (object value, XmlObjectSerializer formatter)
: this (null, null, value, formatter)
{
}
internal DefaultAddressHeader (string name, string ns, object value)
: this (name, ns, value, null) {}
internal DefaultAddressHeader (string name, string ns, object value, XmlObjectSerializer formatter)
{
if (formatter == null)
formatter = value != null ? new DataContractSerializer (value.GetType ()) : null;
this.name = name;
this.ns = ns;
this.formatter = formatter;
this.value = value;
}
public override string Name {
get { return name; }
}
public override string Namespace {
get { return ns; }
}
protected override void OnWriteAddressHeaderContents (XmlDictionaryWriter writer)
{
if (value == null)
writer.WriteAttributeString ("i", "nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
else
this.formatter.WriteObject (writer, value);
}
}
}
}

View File

@@ -0,0 +1,81 @@
//
// System.ServiceModel.AddressHeaderCollection.cs
//
// Author: Duncan Mak (duncan@novell.com)
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.Collections.ObjectModel;
using System.ServiceModel;
namespace System.ServiceModel.Channels
{
public sealed class AddressHeaderCollection : ReadOnlyCollection<AddressHeader>
{
static readonly AddressHeader [] empty = new AddressHeader [0];
static IList<AddressHeader> GetList (IEnumerable<AddressHeader> arg)
{
IList<AddressHeader> list = arg as IList<AddressHeader>;
return list != null ? list : new List<AddressHeader> (arg);
}
public AddressHeaderCollection ()
: base (empty)
{
}
public AddressHeaderCollection (IEnumerable<AddressHeader> headers)
: base (GetList (headers))
{
}
public void AddHeadersTo (Message message)
{
if (message == null)
throw new ArgumentNullException ("message");
foreach (AddressHeader header in this)
message.Headers.Add (header.ToMessageHeader ());
}
public AddressHeader FindHeader (string name, string ns)
{
if (name == null)
throw new ArgumentNullException ("name");
if (ns == null)
throw new ArgumentNullException ("ns");
foreach (AddressHeader header in this)
if (header.Name == name && header.Namespace == ns)
return header;
return null;
}
public AddressHeader[] FindAll (string name, string ns)
{
throw new NotImplementedException ();
}
}
}

View File

@@ -0,0 +1,90 @@
//
// System.ServiceModel.AddressingVersion.cs
//
// Author: Duncan Mak (duncan@novell.com)
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.ServiceModel;
namespace System.ServiceModel.Channels
{
public sealed class AddressingVersion
{
string name;
string address;
string fault_ns;
AddressingVersion (string name, string address, string faultNS)
{
this.name = name;
this.address = address;
this.fault_ns = faultNS;
}
static AddressingVersion addressing200408 = new AddressingVersion (
"Addressing200408",
"http://schemas.xmlsoap.org/ws/2004/08/addressing",
"http://schemas.xmlsoap.org/ws/2004/08/addressing/fault");
static AddressingVersion addressing1_0 = new AddressingVersion (
"Addressing10",
"http://www.w3.org/2005/08/addressing",
"http://www.w3.org/2005/08/addressing/fault");
static AddressingVersion none = new AddressingVersion (
"AddressingNone",
"http://schemas.microsoft.com/ws/2005/05/addressing/none",
null);
public static AddressingVersion WSAddressing10 {
get { return addressing1_0; }
}
public static AddressingVersion WSAddressingAugust2004 {
get { return addressing200408; }
}
public static AddressingVersion None {
get { return none; }
}
internal string Namespace {
get { return address; }
}
internal string FaultNamespace {
get { return fault_ns; }
}
internal string ActionNotSupported {
get { return "ActionNotSupported"; }
}
public override string ToString ()
{
return name + " (" + address + ")";
}
}
}

View File

@@ -0,0 +1,205 @@
//
// AsymmetricSecurityBindingElement.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.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.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net.Security;
using System.IdentityModel.Selectors;
using System.ServiceModel.Channels;
using System.ServiceModel.Channels.Security;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Security;
using System.ServiceModel.Security.Tokens;
namespace System.ServiceModel.Channels
{
public sealed class AsymmetricSecurityBindingElement
: SecurityBindingElement, IPolicyExportExtension
{
public AsymmetricSecurityBindingElement ()
: this (null, null)
{
}
public AsymmetricSecurityBindingElement (
SecurityTokenParameters recipientTokenParameters)
: this (recipientTokenParameters, null)
{
}
public AsymmetricSecurityBindingElement (
SecurityTokenParameters recipientTokenParameters,
SecurityTokenParameters initiatorTokenParameters)
{
this.initiator_token_params = initiatorTokenParameters;
this.recipient_token_params = recipientTokenParameters;
msg_protection_order = MessageProtectionOrder.SignBeforeEncryptAndEncryptSignature;
}
private AsymmetricSecurityBindingElement (
AsymmetricSecurityBindingElement other)
: base (other)
{
msg_protection_order = other.msg_protection_order;
require_sig_confirm = other.require_sig_confirm;
if (other.initiator_token_params != null)
initiator_token_params = other.initiator_token_params.Clone ();
if (other.recipient_token_params != null)
recipient_token_params = other.recipient_token_params.Clone ();
allow_serialized_sign = other.allow_serialized_sign;
}
MessageProtectionOrder msg_protection_order;
SecurityTokenParameters initiator_token_params,
recipient_token_params;
bool allow_serialized_sign, require_sig_confirm;
public bool AllowSerializedSigningTokenOnReply {
get { return allow_serialized_sign; }
set { allow_serialized_sign = value; }
}
public MessageProtectionOrder MessageProtectionOrder {
get { return msg_protection_order; }
set { msg_protection_order = value; }
}
public SecurityTokenParameters InitiatorTokenParameters {
get { return initiator_token_params; }
set { initiator_token_params = value; }
}
public SecurityTokenParameters RecipientTokenParameters {
get { return recipient_token_params; }
set { recipient_token_params = value; }
}
public bool RequireSignatureConfirmation {
get { return require_sig_confirm; }
set { require_sig_confirm = value; }
}
public override void SetKeyDerivation (bool requireDerivedKeys)
{
base.SetKeyDerivation (requireDerivedKeys);
if (InitiatorTokenParameters != null)
InitiatorTokenParameters.RequireDerivedKeys = requireDerivedKeys;
if (RecipientTokenParameters != null)
RecipientTokenParameters.RequireDerivedKeys = requireDerivedKeys;
}
[MonoTODO]
public override string ToString ()
{
return base.ToString ();
}
[MonoTODO]
protected override IChannelFactory<TChannel>
BuildChannelFactoryCore<TChannel> (
BindingContext context)
{
if (InitiatorTokenParameters == null)
throw new InvalidOperationException ("InitiatorTokenParameters must be set before building channel factory.");
if (RecipientTokenParameters == null)
throw new InvalidOperationException ("RecipientTokenParameters must be set before building channel factory.");
SetIssuerBindingContextIfRequired (InitiatorTokenParameters, context);
SetIssuerBindingContextIfRequired (RecipientTokenParameters, context);
ClientCredentials cred = context.BindingParameters.Find<ClientCredentials> ();
if (cred == null)
// it happens when there is no ChannelFactory<T>.
cred = new ClientCredentials ();
SecurityTokenManager manager = cred.CreateSecurityTokenManager ();
ChannelProtectionRequirements requirements =
context.BindingParameters.Find<ChannelProtectionRequirements> ();
return new SecurityChannelFactory<TChannel> (
context.BuildInnerChannelFactory<TChannel> (), new InitiatorMessageSecurityBindingSupport (GetCapabilities (), manager, requirements));
}
[MonoTODO]
protected override IChannelListener<TChannel>
BuildChannelListenerCore<TChannel> (
BindingContext context)
{
if (InitiatorTokenParameters == null)
throw new InvalidOperationException ("InitiatorTokenParameters must be set before building channel factory.");
if (RecipientTokenParameters == null)
throw new InvalidOperationException ("RecipientTokenParameters must be set before building channel factory.");
SetIssuerBindingContextIfRequired (InitiatorTokenParameters, context);
SetIssuerBindingContextIfRequired (RecipientTokenParameters, context);
ServiceCredentials cred = context.BindingParameters.Find<ServiceCredentials> ();
if (cred == null)
// it happens when there is no ChannelFactory<T>.
cred = new ServiceCredentials ();
ServiceCredentialsSecurityTokenManager manager = (ServiceCredentialsSecurityTokenManager) cred.CreateSecurityTokenManager ();
ChannelProtectionRequirements requirements =
context.BindingParameters.Find<ChannelProtectionRequirements> ();
return new SecurityChannelListener<TChannel> (
context.BuildInnerChannelListener<TChannel> (), new RecipientMessageSecurityBindingSupport (GetCapabilities (), manager, requirements));
}
public override BindingElement Clone ()
{
return new AsymmetricSecurityBindingElement (this);
}
[MonoTODO]
public override T GetProperty<T> (BindingContext context)
{
if (context == null)
throw new ArgumentNullException ("context");
if (typeof (T) == typeof (ISecurityCapabilities))
return (T) (object) GetCapabilities ();
if (typeof (T) == typeof (IdentityVerifier))
throw new NotImplementedException ();
return base.GetProperty<T> (context);
}
AsymmetricSecurityCapabilities GetCapabilities ()
{
return new AsymmetricSecurityCapabilities (this);
}
#region explicit interface implementations
[MonoTODO]
void IPolicyExportExtension.ExportPolicy (
MetadataExporter exporter,
PolicyConversionContext policyContext)
{
throw new NotImplementedException ();
}
#endregion
}
}

View File

@@ -0,0 +1,137 @@
//
// BinaryMessageEncoder.cs
//
// Author: Atsushi Enomoto (atsushi@ximian.com)
//
// Copyright (C) 2005,2009 Novell, Inc (http://www.novell.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.IO;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.Text;
using System.Xml;
namespace System.ServiceModel.Channels
{
internal class BinaryMessageEncoder : MessageEncoder
{
public BinaryMessageEncoder ()
{
}
public BinaryMessageEncoder (BinaryMessageEncoderFactory owner, bool session)
{
this.owner = owner;
this.session = session;
}
BinaryMessageEncoderFactory owner;
bool session;
internal bool UseSession {
get { return session; }
}
public override string ContentType {
get { return MediaType; }
}
public override string MediaType {
get { return session ? "application/soap+msbinsession1" : "application/soap+msbin1"; }
}
public override MessageVersion MessageVersion {
get { return MessageVersion.Default; }
}
[MonoTODO]
public override Message ReadMessage (ArraySegment<byte> buffer,
BufferManager bufferManager, string contentType)
{
if (contentType != null && contentType != ContentType)
throw new ProtocolException ("Only content type 'application/soap+msbin1' is allowed.");
// FIXME: retrieve reader session and message body.
throw new NotImplementedException ();
/*
// FIXME: use bufferManager
return Message.CreateMessage (
XmlDictionaryReader.CreateBinaryReader (
buffer.Array, buffer.Offset, buffer.Count,
soap_dictionary,
owner != null ? owner.Owner.ReaderQuotas : new XmlDictionaryReaderQuotas ()),
int.MaxValue, MessageVersion);
*/
}
// It is sort of nasty hack, but there is no other way to provide reader/writer session from TCP stream.
internal XmlBinaryReaderSession CurrentReaderSession { get; set; }
internal XmlBinaryWriterSession CurrentWriterSession { get; set; }
public override Message ReadMessage (Stream stream,
int maxSizeOfHeaders, string contentType)
{
if (contentType != null && contentType != ContentType)
throw new ProtocolException ("Only content type 'application/soap+msbin1' is allowed.");
// FIXME: remove this extraneous buffering. It is somehow required for HTTP + binary encoding binding. The culprit is probably in binary xml reader or writer, but not sure.
if (!stream.CanSeek) {
var tmpms = new MemoryStream ();
var bytes = new byte [4096];
int len;
do {
len = stream.Read (bytes, 0, bytes.Length);
tmpms.Write (bytes, 0, len);
} while (len > 0);
tmpms.Seek (0, SeekOrigin.Begin);
stream = tmpms;
}
var ret = Message.CreateMessage (
XmlDictionaryReader.CreateBinaryReader (stream, Constants.SoapDictionary, owner != null ? owner.Owner.ReaderQuotas : new XmlDictionaryReaderQuotas (), session ? CurrentReaderSession : null),
maxSizeOfHeaders, MessageVersion);
ret.Properties.Encoder = this;
return ret;
}
public override void WriteMessage (Message message, Stream stream)
{
VerifyMessageVersion (message);
using (var xw = XmlDictionaryWriter.CreateBinaryWriter (stream, Constants.SoapDictionary, session ? CurrentWriterSession : null))
message.WriteMessage (xw);
}
[MonoTODO]
public override ArraySegment<byte> WriteMessage (
Message message, int maxMessageSize,
BufferManager bufferManager, int messageOffset)
{
VerifyMessageVersion (message);
throw new NotImplementedException ();
}
}
}

View File

@@ -0,0 +1,64 @@
//
// BinaryMessageEncoderFactory.cs
//
// Author: Atsushi Enomoto (atsushi@ximian.com)
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.ObjectModel;
using System.ServiceModel;
using System.Text;
namespace System.ServiceModel.Channels
{
internal class BinaryMessageEncoderFactory : MessageEncoderFactory
{
BinaryMessageEncodingBindingElement owner;
BinaryMessageEncoder encoder;
public BinaryMessageEncoderFactory (
BinaryMessageEncodingBindingElement owner)
{
this.owner = owner;
encoder = new BinaryMessageEncoder (this, false);
}
public BinaryMessageEncodingBindingElement Owner {
get { return owner; }
}
[MonoTODO]
public override MessageEncoder Encoder {
get { return encoder; }
}
public override MessageVersion MessageVersion {
get { return MessageVersion.Default; }
}
public override MessageEncoder CreateSessionEncoder ()
{
return new BinaryMessageEncoder (this, true);
}
}
}

View File

@@ -0,0 +1,167 @@
//
// BinaryMessageEncodingBindingElement.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.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.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Text;
using System.Xml;
namespace System.ServiceModel.Channels
{
[MonoTODO]
public sealed class BinaryMessageEncodingBindingElement
: MessageEncodingBindingElement,
IWsdlExportExtension, IPolicyExportExtension
{
int max_session_size;
// FIXME: they might be configurable.
int max_read_pool_size = 64;
int max_write_pool_size = 16;
XmlDictionaryReaderQuotas quotas =
new XmlDictionaryReaderQuotas ();
MessageVersion version = MessageVersion.Default;
public BinaryMessageEncodingBindingElement ()
{
}
private BinaryMessageEncodingBindingElement (
BinaryMessageEncodingBindingElement other)
{
throw new NotImplementedException ();
}
public override MessageVersion MessageVersion {
get { return version; }
set {
if (!version.Envelope.Equals (EnvelopeVersion.Soap12))
throw new InvalidOperationException ("Binary message encoding binding element only supports SOAP 1.2.");
version = value;
}
}
public int MaxSessionSize {
get { return max_session_size; }
set { max_session_size = value; }
}
public int MaxReadPoolSize {
get { return max_read_pool_size; }
set { max_read_pool_size = value; }
}
public int MaxWritePoolSize {
get { return max_write_pool_size; }
set { max_write_pool_size = value; }
}
public XmlDictionaryReaderQuotas ReaderQuotas {
get { return quotas; }
#if NET_4_0
set { quotas = value; }
#endif
}
public override IChannelFactory<TChannel> BuildChannelFactory<TChannel> (
BindingContext context)
{
if (context == null)
throw new ArgumentNullException ("context");
//context.RemainingBindingElements.Add (this);
return base.BuildChannelFactory<TChannel> (context);
}
#if !NET_2_1
public override IChannelListener<TChannel> BuildChannelListener<TChannel> (
BindingContext context)
{
if (context == null)
throw new ArgumentNullException ("context");
//context.RemainingBindingElements.Add (this);
return base.BuildChannelListener<TChannel> (context);
}
public override bool CanBuildChannelListener<TChannel> (
BindingContext context)
{
if (context == null)
throw new ArgumentNullException ("context");
return context.CanBuildInnerChannelListener<TChannel> ();
}
#endif
public override BindingElement Clone ()
{
return new BinaryMessageEncodingBindingElement (this);
}
public override T GetProperty<T> (BindingContext context)
{
if (typeof (T) == typeof (MessageVersion))
return (T) (object) MessageVersion;
return null;
}
public override MessageEncoderFactory
CreateMessageEncoderFactory ()
{
return new BinaryMessageEncoderFactory (this);
}
#if !NET_2_1
[MonoTODO]
void IWsdlExportExtension.ExportContract (WsdlExporter exporter,
WsdlContractConversionContext context)
{
throw new NotImplementedException ();
}
void IWsdlExportExtension.ExportEndpoint (WsdlExporter exporter,
WsdlEndpointConversionContext context)
{
}
void IPolicyExportExtension.ExportPolicy (MetadataExporter exporter,
PolicyConversionContext context)
{
PolicyAssertionCollection assertions = context.GetBindingAssertions ();
XmlDocument doc = new XmlDocument ();
assertions.Add (doc.CreateElement ("msb", "BinaryEncoding", "http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1"));
}
#endif
#if NET_4_5
[MonoTODO]
public CompressionFormat CompressionFormat {
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
#endif
}
}

View File

@@ -0,0 +1,312 @@
//
// Binding.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.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.ServiceModel.Channels;
using System.ServiceModel.Description;
namespace System.ServiceModel.Channels
{
public abstract class Binding : IDefaultCommunicationTimeouts
{
string name, ns;
TimeSpan open_timeout, close_timeout;
TimeSpan receive_timeout, send_timeout;
protected Binding ()
{
Initialize ();
name = GetType ().Name;
ns = "http://tempuri.org/";
}
protected Binding (string name, string ns)
{
this.name = name;
this.ns = ns;
Initialize ();
}
public TimeSpan CloseTimeout {
get { return close_timeout; }
set { close_timeout = value; }
}
public TimeSpan OpenTimeout {
get { return open_timeout; }
set { open_timeout = value; }
}
public TimeSpan ReceiveTimeout {
get { return receive_timeout; }
set { receive_timeout = value; }
}
public TimeSpan SendTimeout {
get { return send_timeout; }
set { send_timeout = value; }
}
public string Name {
get { return name; }
set { name = value; }
}
public string Namespace {
get { return ns; }
set { ns = value; }
}
public abstract string Scheme { get; }
public MessageVersion MessageVersion {
get { return GetProperty<MessageVersion> (new BindingParameterCollection ()); }
}
BindingContext CreateContext (
BindingParameterCollection parameters)
{
// FIXME: it seems that binding elements are
// "validated" so that the last item is a transport.
return new BindingContext (
new CustomBinding (this), parameters);
}
BindingContext CreateContext (
Uri listenUriBaseAddress,
string listenUriRelativeAddress,
ListenUriMode listenUriMode,
BindingParameterCollection parameters)
{
// FIXME: it seems that binding elements are
// "validated" so that the last item is a transport.
return new BindingContext (
new CustomBinding (this),
parameters,
listenUriBaseAddress,
listenUriRelativeAddress,
listenUriMode);
}
public IChannelFactory<TChannel>
BuildChannelFactory<TChannel> (
params object [] parameters)
{
BindingParameterCollection pl =
new BindingParameterCollection ();
foreach (object o in parameters)
pl.Add (o);
return BuildChannelFactory<TChannel> (pl);
}
public virtual IChannelFactory<TChannel>
BuildChannelFactory<TChannel> (
BindingParameterCollection parameters)
{
if (parameters == null)
throw new ArgumentNullException ("parameters");
return CreateContext (parameters).BuildInnerChannelFactory<TChannel> ();
}
#if !NET_2_1
public virtual IChannelListener<TChannel>
BuildChannelListener<TChannel> (
Uri listenUriBaseAddress,
string listenUriRelativeAddress,
ListenUriMode listenUriMode,
params object [] parameters)
where TChannel : class, IChannel
{
BindingParameterCollection pl =
new BindingParameterCollection ();
foreach (object o in parameters)
pl.Add (o);
return BuildChannelListener<TChannel> (
listenUriBaseAddress,
listenUriRelativeAddress,
listenUriMode,
pl);
}
public virtual IChannelListener<TChannel>
BuildChannelListener<TChannel> (
Uri listenUriBaseAddress,
string listenUriRelativeAddress,
ListenUriMode listenUriMode,
BindingParameterCollection parameters)
where TChannel : class, IChannel
{
if (listenUriBaseAddress == null)
throw new ArgumentNullException ("listenUriBaseAddress");
if (listenUriRelativeAddress == null)
throw new ArgumentNullException ("listenUriRelativeAddress");
if (parameters == null)
throw new ArgumentNullException ("parameters");
BindingContext ctx = CreateContext (listenUriBaseAddress,
listenUriRelativeAddress,
listenUriMode,
parameters);
return ctx.BuildInnerChannelListener<TChannel> ();
}
public virtual IChannelListener<TChannel>
BuildChannelListener<TChannel> (
Uri listenUri,
params object [] parameters)
where TChannel : class, IChannel
{
BindingParameterCollection pl =
new BindingParameterCollection ();
foreach (object o in parameters)
pl.Add (o);
return BuildChannelListener<TChannel> (listenUri, pl);
}
public virtual IChannelListener<TChannel>
BuildChannelListener<TChannel> (
Uri listenUri,
BindingParameterCollection parameters)
where TChannel : class, IChannel
{
return BuildChannelListener<TChannel> (listenUri,
String.Empty, parameters);
}
public virtual IChannelListener<TChannel>
BuildChannelListener<TChannel> (
Uri listenUriBaseAddress,
string listenUriRelativeAddress,
params object [] parameters)
where TChannel : class, IChannel
{
BindingParameterCollection pl =
new BindingParameterCollection ();
foreach (object o in parameters)
pl.Add (o);
return BuildChannelListener<TChannel> (
listenUriBaseAddress, listenUriRelativeAddress, pl);
}
public virtual IChannelListener<TChannel>
BuildChannelListener<TChannel> (
Uri listenUriBaseAddress,
string listenUriRelativeAddress,
BindingParameterCollection parameters)
where TChannel : class, IChannel
{
return BuildChannelListener<TChannel> (
listenUriBaseAddress,
listenUriRelativeAddress,
ListenUriMode.Explicit,
parameters);
}
public virtual IChannelListener<TChannel>
BuildChannelListener<TChannel> (
params object [] parameters)
where TChannel : class, IChannel
{
BindingParameterCollection pl =
new BindingParameterCollection ();
foreach (object o in parameters)
pl.Add (o);
return BuildChannelListener<TChannel> (pl);
}
public virtual IChannelListener<TChannel>
BuildChannelListener<TChannel> (
BindingParameterCollection parameters)
where TChannel : class, IChannel
{
if (parameters == null)
throw new ArgumentNullException ("parameters");
return CreateContext (parameters).BuildInnerChannelListener<TChannel> ();
}
#endif
public bool CanBuildChannelFactory<TChannel> (
params object [] parameters)
{
BindingParameterCollection pl =
new BindingParameterCollection ();
foreach (object o in parameters)
pl.Add (o);
return CanBuildChannelFactory<TChannel> (pl);
}
public virtual bool CanBuildChannelFactory<TChannel> (
BindingParameterCollection parameters)
{
if (parameters == null)
throw new ArgumentNullException ("parameters");
return CreateContext (parameters).CanBuildInnerChannelFactory<TChannel> ();
}
#if !NET_2_1
public bool CanBuildChannelListener<TChannel> (
params object [] parameters)
where TChannel : class, IChannel
{
BindingParameterCollection pl =
new BindingParameterCollection ();
foreach (object o in parameters)
pl.Add (o);
return CanBuildChannelListener<TChannel> (pl);
}
public virtual bool CanBuildChannelListener<TChannel> (
BindingParameterCollection parameters)
where TChannel : class, IChannel
{
if (parameters == null)
throw new ArgumentNullException ("parameters");
return CreateContext (parameters).CanBuildInnerChannelListener<TChannel> ();
}
#endif
public abstract BindingElementCollection CreateBindingElements ();
public T GetProperty<T> (BindingParameterCollection parameters)
where T : class
{
if (parameters == null)
throw new ArgumentNullException ("parameters");
return CreateContext (parameters).GetInnerProperty<T> ();
}
private void Initialize ()
{
IDefaultCommunicationTimeouts t =
DefaultCommunicationTimeouts.Instance;
open_timeout = t.OpenTimeout;
close_timeout = t.CloseTimeout;
receive_timeout = t.ReceiveTimeout;
send_timeout = t.SendTimeout;
}
}
}

View File

@@ -0,0 +1,195 @@
//
// BindingContext.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005-2006 Novell, Inc. http://www.novell.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.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Security;
namespace System.ServiceModel.Channels
{
public class BindingContext
{
CustomBinding binding;
BindingParameterCollection parameters;
Uri listen_uri_base;
string listen_uri_relative;
ListenUriMode listen_uri_mode;
BindingElementCollection elements; // for internal use
public BindingContext (CustomBinding binding,
BindingParameterCollection parms)
{
if (binding == null)
throw new ArgumentNullException ("binding");
if (parms == null)
throw new ArgumentNullException ("parms");
this.binding = binding;
parameters = new BindingParameterCollection ();
foreach (var item in parms)
parameters.Add (item);
this.elements = new BindingElementCollection ();
foreach (var item in binding.Elements)
this.elements.Add (item);
}
public BindingContext (CustomBinding binding,
BindingParameterCollection parameters,
Uri listenUriBaseAddress,
string listenUriRelativeAddress,
ListenUriMode listenUriMode)
: this (binding, parameters)
{
listen_uri_base = listenUriBaseAddress;
listen_uri_relative = listenUriRelativeAddress;
listen_uri_mode = listenUriMode;
}
// deep clone .ctor().
BindingContext (CustomBinding binding,
BindingParameterCollection parms,
BindingElementCollection elems,
Uri listenUriBaseAddress,
string listenUriRelativeAddress,
ListenUriMode listenUriMode)
{
this.binding = new CustomBinding (binding);
parameters = new BindingParameterCollection ();
foreach (var item in parms)
parameters.Add (item);
this.elements = new BindingElementCollection ();
foreach (var item in elems)
this.elements.Add (item);
listen_uri_base = listenUriBaseAddress;
listen_uri_relative = listenUriRelativeAddress;
listen_uri_mode = listenUriMode;
}
public CustomBinding Binding {
get { return binding; }
}
public BindingParameterCollection BindingParameters {
get { return parameters; }
}
public Uri ListenUriBaseAddress {
get { return listen_uri_base; }
set { listen_uri_base = value; }
}
public string ListenUriRelativeAddress {
get { return listen_uri_relative; }
set { listen_uri_relative = value; }
}
public ListenUriMode ListenUriMode {
get { return listen_uri_mode; }
set { listen_uri_mode = value; }
}
public BindingElementCollection RemainingBindingElements {
get {
if (elements == null)
elements = binding.CreateBindingElements ();
return elements;
}
}
internal BindingElement DequeueBindingElement ()
{
return DequeueBindingElement (true);
}
BindingElement DequeueBindingElement (bool raiseError)
{
if (RemainingBindingElements.Count == 0) {
if (raiseError)
throw new InvalidOperationException ("There is no more available binding element.");
else
return null;
}
BindingElement el = RemainingBindingElements [0];
RemainingBindingElements.RemoveAt (0);
return el;
}
public IChannelFactory<TChannel>
BuildInnerChannelFactory<TChannel> ()
{
BindingContext ctx = this.Clone ();
return ctx.DequeueBindingElement ().BuildChannelFactory<TChannel> (ctx);
}
#if !NET_2_1
public IChannelListener<TChannel>
BuildInnerChannelListener<TChannel> ()
where TChannel : class, IChannel
{
BindingContext ctx = this.Clone ();
var be = ctx.DequeueBindingElement (false);
if (be == null)
throw new InvalidOperationException ("There is likely no TransportBindingElement that can build a channel listener in this binding context");
return be.BuildChannelListener<TChannel> (ctx);
}
#endif
public bool CanBuildInnerChannelFactory<TChannel> ()
{
BindingContext ctx = this.Clone ();
return ctx.DequeueBindingElement ().CanBuildChannelFactory<TChannel> (ctx);
}
#if !NET_2_1
public bool CanBuildInnerChannelListener<TChannel> ()
where TChannel : class, IChannel
{
BindingContext ctx = this.Clone ();
var be = ctx.DequeueBindingElement (false);
if (be == null)
throw new InvalidOperationException ("There is likely no TransportBindingElement that can build a channel listener in this binding context");
return be.CanBuildChannelListener<TChannel> (ctx);
}
#endif
public T GetInnerProperty<T> () where T : class
{
BindingContext ctx = this.Clone ();
BindingElement e = ctx.DequeueBindingElement (false);
return e == null ? default (T) : e.GetProperty<T> (ctx);
}
public BindingContext Clone ()
{
return new BindingContext (this.binding, this.parameters, this.elements, this.listen_uri_base, this.listen_uri_relative, this.listen_uri_mode);
}
}
}

View File

@@ -0,0 +1,87 @@
//
// BindingElement.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.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.ServiceModel.Description;
using System.ServiceModel.Security;
using System.ServiceModel.Channels;
namespace System.ServiceModel.Channels
{
public abstract class BindingElement
{
protected BindingElement ()
{
}
[MonoTODO]
protected BindingElement (BindingElement other)
{
}
public virtual IChannelFactory<TChannel>
BuildChannelFactory<TChannel> (BindingContext context)
{
if (context == null)
throw new ArgumentNullException ("context");
return context.BuildInnerChannelFactory<TChannel> ();
}
#if !NET_2_1
public virtual IChannelListener<TChannel>
BuildChannelListener<TChannel> (
BindingContext context)
where TChannel : class, IChannel
{
if (context == null)
throw new ArgumentNullException ("context");
return context.BuildInnerChannelListener<TChannel> ();
}
#endif
public virtual bool CanBuildChannelFactory<TChannel> (
BindingContext context)
{
return context.CanBuildInnerChannelFactory<TChannel> ();
}
#if !NET_2_1
public virtual bool CanBuildChannelListener<TChannel> (
BindingContext context)
where TChannel : class, IChannel
{
return context.CanBuildInnerChannelListener<TChannel> ();
}
#endif
public abstract BindingElement Clone ();
public abstract T GetProperty<T> (BindingContext context)
where T : class;
}
}

View File

@@ -0,0 +1,122 @@
//
// BindingElementCollection.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.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.Collections.ObjectModel;
namespace System.ServiceModel.Channels
{
[MonoTODO]
public class BindingElementCollection : Collection<BindingElement>
{
public BindingElementCollection ()
{
}
public BindingElementCollection (BindingElement [] bindings)
{
AddRange (bindings);
}
public BindingElementCollection (IEnumerable<BindingElement> bindings)
{
foreach (BindingElement e in bindings)
Add (e);
}
public void AddRange (params BindingElement[] elements)
{
foreach (BindingElement e in elements)
Add (e);
}
public BindingElementCollection Clone ()
{
return new BindingElementCollection (this);
}
public bool Contains (Type bindingElementType)
{
foreach (BindingElement b in this)
if (bindingElementType.IsAssignableFrom (b.GetType ()))
return true;
return false;
}
public T Find<T> ()
{
foreach (BindingElement b in this)
if ((object) b is T)
return (T) (object) b;
return default (T);
}
public Collection<T> FindAll<T> ()
{
Collection<T> coll = new Collection<T> ();
foreach (BindingElement b in this)
if ((object) b is T)
coll.Add ((T) (object) b);
return coll;
}
public T Remove<T> ()
{
foreach (BindingElement b in this) {
if ((object) b is T) {
Remove (b);
return (T) (object) b;
}
}
return default (T);
}
public Collection<T> RemoveAll<T> ()
{
Collection<T> coll = new Collection<T> ();
foreach (BindingElement b in this) {
if ((object) b is T) {
Remove (b);
coll.Add ((T) (object) b);
}
}
return coll;
}
protected override void InsertItem (int index,
BindingElement item)
{
Items.Insert (index, item);
}
protected override void SetItem (int index, BindingElement item)
{
Items [index] = item;
}
}
}

View File

@@ -0,0 +1,53 @@
//
// BindingParameterCollection.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.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;
namespace System.ServiceModel.Channels
{
public class BindingParameterCollection
: KeyedByTypeCollection<object>
{
#if NET_4_5
protected override Type GetKeyForItem (object item)
{
return base.GetKeyForItem (item);
}
protected override void InsertItem (int index, object item)
{
base.InsertItem (index, item);
}
protected override void SetItem (int index, object item)
{
base.SetItem (index, item);
}
#endif
}
}

View File

@@ -0,0 +1,98 @@
//
// BodyWriter.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005,2009 Novell, Inc. http://www.novell.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.ObjectModel;
using System.IO;
using System.Runtime.Serialization;
using System.Xml;
namespace System.ServiceModel.Channels
{
public abstract class BodyWriter
{
bool is_buffered;
protected BodyWriter (bool isBuffered)
{
is_buffered = isBuffered;
}
public bool IsBuffered {
get { return is_buffered; }
}
public BodyWriter CreateBufferedCopy (
int maxBufferSize)
{
return OnCreateBufferedCopy (maxBufferSize);
}
public void WriteBodyContents (XmlDictionaryWriter writer)
{
OnWriteBodyContents (writer);
}
protected virtual BodyWriter OnCreateBufferedCopy (
int maxBufferSize)
{
var s = new XmlWriterSettings ();
s.OmitXmlDeclaration = true;
s.ConformanceLevel = ConformanceLevel.Auto;
StringWriter sw = new StringWriter ();
using (XmlDictionaryWriter w = XmlDictionaryWriter.CreateDictionaryWriter (XmlWriter.Create (sw, s)))
WriteBodyContents (w);
var xml = sw.ToString ();
if (xml.Length > 0)
return new XmlReaderBodyWriter (xml, maxBufferSize, null);
else
return new EmptyBodyWriter ();
}
protected abstract void OnWriteBodyContents (
XmlDictionaryWriter writer);
class EmptyBodyWriter : BodyWriter
{
public EmptyBodyWriter ()
: base (true)
{
}
protected override BodyWriter OnCreateBufferedCopy (
int maxBufferSize)
{
return new EmptyBodyWriter ();
}
protected override void OnWriteBodyContents (XmlDictionaryWriter writer)
{
// nothing to do
}
}
}
}

View File

@@ -0,0 +1,225 @@
//
// BufferManager.cs:
// This class suffers from an engineering problem in its
// design: when this API is used to limit the total pool
// size it will throw, but no user code is designed to
// cope with that.
//
// Instead of the Microsoft strategy, we allow allocation
// to go as far as it wants to go and merely allow this
// to be a pool that can be used recycle buffers.
//
// This still gives us the main benefit of this class, while
// avoiding the potential crashing scenarios and simplifies
// the implementation significantly from what has been
// document in the blogosphere.
//
// There are a few problems: for example, if we do not find
// a buffer of the proper size in the expected slot, say
// a 31k buffer in the slot for [32k-64k] values, we will
// allocate a new buffer, even if there might have been a
// buffer for 128k.
//
// A few considerations:
//
// The size of an empty array is either 16 on 32 bit systems
// and 32 bytes in 64 bit systems.
//
// We take this information into account for the minimum allocation
// pools.
//
// Authors:
// Atsushi Enomoto (atsushi@ximian.com)
// Miguel de Icaza (miguel@gnome.org)
//
// Copyright (C) 2005, 2010 Novell, Inc (http://www.novell.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.IO;
using System.Collections.ObjectModel;
using System.ServiceModel;
namespace System.ServiceModel.Channels
{
public abstract class BufferManager
{
protected BufferManager ()
{
}
public abstract void Clear ();
public static BufferManager CreateBufferManager (
long maxBufferPoolSize, int maxBufferSize)
{
return new DefaultBufferManager (maxBufferPoolSize, maxBufferSize);
}
public abstract void ReturnBuffer (byte[] buffer);
public abstract byte[] TakeBuffer (int bufferSize);
#if DEBUG_BUFFER
internal abstract void DumpStats ();
#endif
class DefaultBufferManager : BufferManager
{
const int log_min = 5; // Anything smaller than 1 << log_cut goes into the first bucket
long max_pool_size;
int max_size;
List<byte []> [] buffers = new List<byte []> [32-log_min];
#if DEBUG_BUFFER
internal override void DumpStats ()
{
Console.WriteLine ("- hit={0} miss={1}-", hits, miss);
for (int i = 0; i < buffers.Length; i++){
if (buffers [i] == null)
continue;
Console.Write ("Slot {0} - {1} [", i, buffers [i].Count);
byte [][] arr = buffers [i].ToArray ();
for (int j = 0; j < Math.Min (3, arr.Length); j++)
Console.Write ("{0} ", arr [j].Length);
Console.WriteLine ("]");
}
}
#endif
static int log2 (uint n)
{
int pos = 0;
if (n >= 1<<16) {
n >>= 16;
pos += 16;
}
if (n >= 1<< 8) {
n >>= 8;
pos += 8;
}
if (n >= 1<< 4) {
n >>= 4;
pos += 4;
}
if (n >= 1<< 2) {
n >>= 2;
pos += 2;
}
if (n >= 1<< 1)
pos += 1;
return ((n == 0) ? (-1) : pos);
}
public DefaultBufferManager (long maxBufferPoolSize, int maxBufferSize)
{
this.max_pool_size = maxBufferPoolSize;
this.max_size = maxBufferSize;
}
public override void Clear ()
{
foreach (var stack in buffers){
if (stack == null)
continue;
stack.Clear ();
}
Array.Clear (buffers, 0, buffers.Length);
}
public override void ReturnBuffer (byte [] buffer)
{
if (buffer == null)
return;
uint size = (uint) buffer.Length;
int l2 = log2 (size);
if (l2 > log_min)
l2 -= log_min;
List<byte []> returned = buffers [l2];
if (returned == null)
returned = buffers [l2] = new List<byte []> ();
returned.Add (buffer);
}
int hits, miss;
public override byte [] TakeBuffer (int bufferSize)
{
if (bufferSize < 0 || (max_size >= 0 && bufferSize > max_size))
throw new ArgumentOutOfRangeException ();
int l2 = log2 ((uint) bufferSize);
if (l2 > log_min)
l2 -= log_min;
List<byte []> returned = buffers [l2];
if (returned == null || returned.Count == 0)
return new byte [bufferSize];
foreach (var e in returned){
if (e.Length >= bufferSize){
hits++;
returned.Remove (e);
return e;
}
}
return new byte [bufferSize];
}
}
}
#if DEBUG_BUFFER
class Foo {
static void Main ()
{
var a = BufferManager.CreateBufferManager (1024*1024, 1024*1024);
var rand = new Random (0);
var buffs = new List<byte []> ();
for (int i = 0; i < 4096; i++){
a.DumpStats ();
var request = rand.Next (1,1024*1024);
if ((i % 2) == 0)
request = rand.Next (1024, 4096);
var x = a.TakeBuffer (request);
if (x.Length < request)
throw new Exception ();
Console.WriteLine ("Delta={2} Requested {0} got={1} bytes ", request, x.Length, x.Length-request);
if ((i % 3) == 0){
Console.WriteLine ("Return: {0}", x.Length);
a.ReturnBuffer (x);
}
else
buffs.Add (x);
}
a.DumpStats ();
}
}
#endif
}

View File

@@ -0,0 +1,187 @@
//
// CachingCompiler
//
// Authors:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
// Ankit Jain (jankit@novell.com)
//
// (C) 2002 Ximian, Inc (http://www.ximian.com)
// (c) Copyright Novell, Inc. (http://www.novell.com)
// Copyright (C) 2006 Novell, Inc. http://www.novell.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.
//
// Code taken from System.Web.Compilation.CachingCompiler
//
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.Caching;
using System.Web.Configuration;
namespace System.ServiceModel.Channels
{
class CachingCompiler
{
static string dynamicBase = AppDomain.CurrentDomain.SetupInformation.DynamicBase;
static Hashtable compilationTickets = new Hashtable ();
public const string cachePrefix = "@@Assembly";
public const string cacheTypePrefix = "@@@Type";
public static void InsertTypeFileDep (Type type, string filename)
{
CacheDependency dep = new CacheDependency (filename);
HttpRuntime.Cache.Insert (cacheTypePrefix + filename, type, dep);
}
public static void InsertType (Type type, string filename, string key,
CacheItemRemovedCallback removed_callback)
{
//string [] cacheKeys = new string [] { cachePrefix + filename };
//CacheDependency dep = new CacheDependency (null, cacheKeys);
CacheDependency dep = new CacheDependency (filename);
HttpRuntime.Cache.Insert (cacheTypePrefix + key, type, dep,
Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,
CacheItemPriority.Normal, removed_callback);
}
public static Type GetTypeFromCache (string filename)
{
return (Type) HttpRuntime.Cache [cacheTypePrefix + filename];
}
internal static CompilerParameters GetOptions (ICollection assemblies)
{
CompilerParameters options = new CompilerParameters ();
if (assemblies != null) {
StringCollection coll = options.ReferencedAssemblies;
foreach (string str in assemblies)
coll.Add (str);
}
return options;
}
public static CompilerResults Compile (string language, string key, string source,
string filename, ArrayList assemblies)
{
Cache cache = HttpRuntime.Cache;
CompilerResults results = (CompilerResults) cache [cachePrefix + key];
if (results != null)
return results;
if (!Directory.Exists (dynamicBase))
Directory.CreateDirectory (dynamicBase);
object ticket;
bool acquired = AcquireCompilationTicket (cachePrefix + key, out ticket);
try {
Monitor.Enter (ticket);
results = (CompilerResults) cache [cachePrefix + key];
if (results != null)
return results;
CompilationSection config = (CompilationSection) WebConfigurationManager.GetSection ("system.web/compilation");
Compiler c = config.Compilers[language];
Type t = Type.GetType (c.Type, true);
CodeDomProvider provider = Activator.CreateInstance (t) as CodeDomProvider;
if (provider == null)
throw new HttpException ("Configuration error. Language not supported: " +
language, 500);
CompilerParameters options = GetOptions (assemblies);
TempFileCollection tempcoll = new TempFileCollection (config.TempDirectory, true);
string dllfilename = Path.GetFileName (tempcoll.AddExtension ("dll", true));
options.OutputAssembly = Path.Combine (dynamicBase, dllfilename);
results = provider.CompileAssemblyFromSource (options, source);
ArrayList realdeps = new ArrayList (assemblies.Count + 1);
realdeps.Add (filename);
for (int i = assemblies.Count - 1; i >= 0; i--) {
string current = (string) assemblies [i];
if (Path.IsPathRooted (current))
realdeps.Add (current);
}
string [] deps = (string []) realdeps.ToArray (typeof (string));
//cache results
cache.Insert (cachePrefix + key, results, new CacheDependency (deps));
} finally {
Monitor.Exit (ticket);
if (acquired)
ReleaseCompilationTicket (cachePrefix + key);
}
return results;
}
public static Type CompileAndGetType (ServiceHostParser parser,
string key, CacheItemRemovedCallback removed_callback)
{
CompilerResults result = CachingCompiler.Compile (parser.Language, key, parser.Program, parser.Filename, parser.Assemblies);
if (result.NativeCompilerReturnValue != 0)
throw new CompilationException (parser.Filename, result.Errors, parser.Program);
Assembly assembly = result.CompiledAssembly;
if (assembly == null)
throw new CompilationException (parser.Filename, result.Errors, parser.Program);
Type type = assembly.GetType (parser.TypeName, true);
//cache type
InsertType (type, parser.Filename, key, removed_callback);
return type;
}
static bool AcquireCompilationTicket (string key, out object ticket)
{
lock (compilationTickets.SyncRoot) {
ticket = compilationTickets [key];
if (ticket == null) {
ticket = new object ();
compilationTickets [key] = ticket;
return true;
}
}
return false;
}
static void ReleaseCompilationTicket (string key)
{
lock (compilationTickets.SyncRoot) {
compilationTickets.Remove (key);
}
}
}
}

View File

@@ -0,0 +1 @@
6f98db8e2ad9edae4815a2ee4f6ae8977ede21b1

View File

@@ -0,0 +1,93 @@
//
// ChannelBase.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.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.ObjectModel;
using System.Runtime.Serialization;
using System.ServiceModel.Channels;
namespace System.ServiceModel.Channels
{
[MonoTODO]
public abstract class ChannelBase : CommunicationObject,
ICommunicationObject, IChannel,
IDefaultCommunicationTimeouts
{
ChannelManagerBase manager;
protected ChannelBase (ChannelManagerBase manager)
{
this.manager = manager;
}
protected internal override TimeSpan DefaultCloseTimeout {
get { throw new NotImplementedException ("Actually it should be overriden before being used."); }
}
protected internal override TimeSpan DefaultOpenTimeout {
get { throw new NotImplementedException ("Actually it should be overriden before being used."); }
}
protected internal TimeSpan DefaultReceiveTimeout {
get { return manager.DefaultReceiveTimeout; }
}
protected internal TimeSpan DefaultSendTimeout {
get { return manager.DefaultSendTimeout; }
}
protected ChannelManagerBase Manager {
get { return manager; }
}
public virtual T GetProperty<T> () where T : class
{
return null;
}
protected override void OnClosed ()
{
base.OnClosed ();
}
TimeSpan IDefaultCommunicationTimeouts.CloseTimeout {
get { return DefaultCloseTimeout; }
}
TimeSpan IDefaultCommunicationTimeouts.OpenTimeout {
get { return DefaultOpenTimeout; }
}
TimeSpan IDefaultCommunicationTimeouts.ReceiveTimeout {
get { return DefaultReceiveTimeout; }
}
TimeSpan IDefaultCommunicationTimeouts.SendTimeout {
get { return DefaultSendTimeout; }
}
}
}

View File

@@ -0,0 +1,229 @@
//
// ChannelFactoryBase.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Dispatcher;
namespace System.ServiceModel.Channels
{
internal interface IHasMessageEncoder
{
MessageEncoder MessageEncoder { get; }
}
internal abstract class TransportChannelFactoryBase<TChannel> : ChannelFactoryBase<TChannel>, IHasMessageEncoder
{
protected TransportChannelFactoryBase (TransportBindingElement source, BindingContext ctx)
{
Transport = source;
}
public TransportBindingElement Transport { get; private set; }
public MessageEncoder MessageEncoder { get; internal set; }
Action<TimeSpan> open_delegate;
protected override IAsyncResult OnBeginOpen (TimeSpan timeout,
AsyncCallback callback, object state)
{
if (open_delegate == null)
open_delegate = new Action<TimeSpan> (OnOpen);
return open_delegate.BeginInvoke (timeout, callback, state);
}
protected override void OnEndOpen (IAsyncResult result)
{
if (open_delegate == null)
throw new InvalidOperationException ("Async open operation has not started");
open_delegate.EndInvoke (result);
}
protected override void OnOpen (TimeSpan timeout)
{
}
/* commented out as it is in doubt.
public override T GetProperty<T> ()
{
if (typeof (T) == typeof (MessageVersion))
return (T) (object) MessageEncoder.MessageVersion;
return base.GetProperty<T> ();
}
*/
}
public abstract class ChannelFactoryBase<TChannel>
: ChannelFactoryBase, IChannelFactory<TChannel>
{
List<TChannel> channels = new List<TChannel> ();
protected ChannelFactoryBase ()
: this (DefaultCommunicationTimeouts.Instance)
{
}
protected ChannelFactoryBase (
IDefaultCommunicationTimeouts timeouts)
: base (timeouts)
{
}
public TChannel CreateChannel (
EndpointAddress remoteAddress)
{
if (remoteAddress == null)
throw new ArgumentNullException ("remoteAddress");
return CreateChannel (remoteAddress, remoteAddress.Uri);
}
public TChannel CreateChannel (
EndpointAddress remoteAddress, Uri via)
{
if (remoteAddress == null)
throw new ArgumentNullException ("remoteAddress");
if (via == null)
throw new ArgumentNullException ("via");
ValidateCreateChannel ();
var ch = OnCreateChannel (remoteAddress, via);
channels.Add (ch);
return ch;
}
protected abstract TChannel OnCreateChannel (
EndpointAddress remoteAddress, Uri via);
protected override void OnAbort ()
{
// this implicitly premises: TChannel is IChannel
foreach (IChannel ch in channels)
ch.Abort ();
base.OnAbort ();
}
protected override void OnClose (TimeSpan timeout)
{
DateTime start = DateTime.Now;
// this implicitly premises: TChannel is IChannel
foreach (IChannel ch in channels)
ch.Close (timeout - (DateTime.Now - start));
base.OnClose (timeout - (DateTime.Now - start));
}
protected override IAsyncResult OnBeginClose (TimeSpan timeout, AsyncCallback callback, object state)
{
// base impl. will call this.OnClose()
// FIXME: use async BeginClose/EndClose on the channels.
return base.OnBeginClose (timeout, callback, state);
}
protected override void OnEndClose (IAsyncResult result)
{
// base impl. will call this.OnClose()
base.OnEndClose (result);
}
protected void ValidateCreateChannel ()
{
ThrowIfDisposedOrNotOpen ();
if (State == CommunicationState.Faulted)
throw new CommunicationObjectFaultedException ();
}
}
public abstract class ChannelFactoryBase
: ChannelManagerBase, IChannelFactory, ICommunicationObject
{
TimeSpan open_timeout, close_timeout, receive_timeout, send_timeout;
protected ChannelFactoryBase ()
: this (DefaultCommunicationTimeouts.Instance)
{
}
protected ChannelFactoryBase (
IDefaultCommunicationTimeouts timeouts)
{
open_timeout = timeouts.OpenTimeout;
close_timeout = timeouts.CloseTimeout;
send_timeout = timeouts.SendTimeout;
receive_timeout = timeouts.ReceiveTimeout;
}
protected internal override TimeSpan DefaultCloseTimeout {
get { return close_timeout; }
}
protected internal override TimeSpan DefaultOpenTimeout {
get { return open_timeout; }
}
protected internal override TimeSpan DefaultReceiveTimeout {
get { return receive_timeout; }
}
protected internal override TimeSpan DefaultSendTimeout {
get { return send_timeout; }
}
public virtual T GetProperty<T> () where T : class
{
return null;
}
protected override void OnAbort ()
{
// what should we do here?
}
Action<TimeSpan> close_delegate;
protected override IAsyncResult OnBeginClose (TimeSpan timeout, AsyncCallback callback, object state)
{
if (close_delegate == null)
close_delegate = new Action<TimeSpan> (OnClose);
return close_delegate.BeginInvoke (timeout, callback, state);
}
protected override void OnEndClose (IAsyncResult result)
{
if (close_delegate == null)
throw new InvalidOperationException ("Async close operation has not started");
close_delegate.EndInvoke (result);
}
protected override void OnClose (TimeSpan timeout)
{
// what should we do here?
}
}
}

View File

@@ -0,0 +1,123 @@
//
// ChannelListenerBase.cs
//
// Author: Atsushi Enomoto (atsushi@ximian.com)
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.Collections.ObjectModel;
using System.ServiceModel;
namespace System.ServiceModel.Channels
{
[MonoTODO]
public abstract class ChannelListenerBase : ChannelManagerBase,
IChannelListener, ICommunicationObject,
IDefaultCommunicationTimeouts
{
IDefaultCommunicationTimeouts timeouts;
KeyedByTypeCollection<object> properties;
protected ChannelListenerBase ()
: this (DefaultCommunicationTimeouts.Instance)
{
}
protected ChannelListenerBase (
IDefaultCommunicationTimeouts timeouts)
{
this.timeouts = timeouts;
}
public abstract Uri Uri { get; }
protected internal override TimeSpan DefaultCloseTimeout {
get { return timeouts.CloseTimeout; }
}
protected internal override TimeSpan DefaultOpenTimeout {
get { return timeouts.OpenTimeout; }
}
protected internal override TimeSpan DefaultReceiveTimeout {
get { return timeouts.ReceiveTimeout; }
}
protected internal override TimeSpan DefaultSendTimeout {
get { return timeouts.SendTimeout; }
}
TimeSpan IDefaultCommunicationTimeouts.CloseTimeout {
get { return timeouts.CloseTimeout; }
}
TimeSpan IDefaultCommunicationTimeouts.OpenTimeout {
get { return timeouts.OpenTimeout; }
}
TimeSpan IDefaultCommunicationTimeouts.ReceiveTimeout {
get { return timeouts.ReceiveTimeout; }
}
TimeSpan IDefaultCommunicationTimeouts.SendTimeout {
get { return timeouts.SendTimeout; }
}
internal virtual KeyedByTypeCollection<object> Properties {
get {
if (properties == null)
properties = new KeyedByTypeCollection<object> ();
return properties;
}
}
public virtual T GetProperty<T> () where T : class
{
return properties != null ? properties.Find<T> () : null;
}
public IAsyncResult BeginWaitForChannel (
TimeSpan timeout, AsyncCallback callback, object state)
{
return OnBeginWaitForChannel (timeout, callback, state);
}
public bool EndWaitForChannel (IAsyncResult result)
{
return OnEndWaitForChannel (result);
}
public bool WaitForChannel (TimeSpan timeout)
{
return OnWaitForChannel (timeout);
}
protected abstract IAsyncResult OnBeginWaitForChannel (
TimeSpan timeout, AsyncCallback callback, object state);
protected abstract bool OnEndWaitForChannel (IAsyncResult result);
protected abstract bool OnWaitForChannel (TimeSpan timeout);
}
}

View File

@@ -0,0 +1,224 @@
//
// ChannelListenerBase.cs
//
// Author: Atsushi Enomoto (atsushi@ximian.com)
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.ServiceModel;
using System.ServiceModel.Description;
using System.Threading;
namespace System.ServiceModel.Channels
{
internal abstract class InternalChannelListenerBase<TChannel>
: ChannelListenerBase<TChannel>
where TChannel : class, IChannel
{
protected InternalChannelListenerBase (BindingContext context)
: base (context.Binding)
{
// for ListenUriMode(.Unique), the URI uniqueness
// should be assured by the derived types.
listen_uri =
context.ListenUriRelativeAddress != null ?
new Uri (context.ListenUriBaseAddress, context.ListenUriRelativeAddress) :
context.ListenUriBaseAddress;
}
Uri listen_uri;
Func<TimeSpan,TChannel> accept_channel_delegate;
Func<TimeSpan,bool> wait_delegate;
Action<TimeSpan> open_delegate, close_delegate;
public MessageEncoder MessageEncoder { get; internal set; }
public override Uri Uri {
get { return listen_uri; }
}
protected Thread CurrentAsyncThread { get; private set; }
protected IAsyncResult CurrentAsyncResult { get; private set; }
protected override void OnAbort ()
{
if (CurrentAsyncThread != null)
CurrentAsyncThread.Abort (); // it is not beautiful but there is no other way to stop it.
}
protected override void OnClose (TimeSpan timeout)
{
if (CurrentAsyncThread != null)
if (!CancelAsync (timeout))
if (CurrentAsyncThread != null) // being careful
CurrentAsyncThread.Abort (); // it is not beautiful but there is no other way to stop it.
}
// cancel ongoing async operations and return if it was
// completed successfully. If not, it will abort.
public virtual bool CancelAsync (TimeSpan timeout)
{
return CurrentAsyncResult == null || CurrentAsyncResult.AsyncWaitHandle.WaitOne (timeout);
}
protected override IAsyncResult OnBeginAcceptChannel (
TimeSpan timeout, AsyncCallback callback,
object asyncState)
{
//if (CurrentAsyncResult != null)
// throw new InvalidOperationException ("Another AcceptChannel operation is in progress");
ManualResetEvent wait = new ManualResetEvent (false);
if (accept_channel_delegate == null)
accept_channel_delegate = new Func<TimeSpan,TChannel> (delegate (TimeSpan tout) {
wait.WaitOne (); // make sure that CurrentAsyncResult is set.
CurrentAsyncThread = Thread.CurrentThread;
try {
return OnAcceptChannel (tout);
} finally {
CurrentAsyncThread = null;
CurrentAsyncResult = null;
}
});
CurrentAsyncResult = accept_channel_delegate.BeginInvoke (timeout, callback, asyncState);
wait.Set ();
return CurrentAsyncResult;
}
protected override TChannel OnEndAcceptChannel (IAsyncResult result)
{
if (accept_channel_delegate == null)
throw new InvalidOperationException ("Async AcceptChannel operation has not started");
// FIXME: what's wrong with this?
//if (CurrentAsyncResult == null)
// throw new InvalidOperationException ("Async AcceptChannel operation has not started. Argument result was: " + result);
return accept_channel_delegate.EndInvoke (result);
}
protected override IAsyncResult OnBeginWaitForChannel (
TimeSpan timeout, AsyncCallback callback, object state)
{
if (wait_delegate == null)
wait_delegate = new Func<TimeSpan,bool> (OnWaitForChannel);
return wait_delegate.BeginInvoke (timeout, callback, state);
}
protected override bool OnEndWaitForChannel (IAsyncResult result)
{
if (wait_delegate == null)
throw new InvalidOperationException ("Async WaitForChannel operation has not started");
return wait_delegate.EndInvoke (result);
}
protected override IAsyncResult OnBeginOpen (TimeSpan timeout,
AsyncCallback callback, object state)
{
if (open_delegate == null)
open_delegate = new Action<TimeSpan> (OnOpen);
return open_delegate.BeginInvoke (timeout, callback, state);
}
protected override void OnEndOpen (IAsyncResult result)
{
if (open_delegate == null)
throw new InvalidOperationException ("Async Open operation has not started");
open_delegate.EndInvoke (result);
}
protected override IAsyncResult OnBeginClose (TimeSpan timeout,
AsyncCallback callback, object state)
{
if (close_delegate == null)
close_delegate = new Action<TimeSpan> (OnClose);
return close_delegate.BeginInvoke (timeout, callback, state);
}
protected override void OnEndClose (IAsyncResult result)
{
if (close_delegate == null)
throw new InvalidOperationException ("Async Close operation has not started");
close_delegate.EndInvoke (result);
}
}
public abstract class ChannelListenerBase<TChannel>
: ChannelListenerBase, IChannelListener<TChannel>,
IChannelListener, ICommunicationObject
where TChannel : class, IChannel
{
IDefaultCommunicationTimeouts timeouts;
protected ChannelListenerBase ()
: this (DefaultCommunicationTimeouts.Instance)
{
}
protected ChannelListenerBase (
IDefaultCommunicationTimeouts timeouts)
{
if (timeouts == null)
throw new ArgumentNullException ("timeouts");
this.timeouts = timeouts;
}
public TChannel AcceptChannel ()
{
return AcceptChannel (timeouts.ReceiveTimeout);
}
public TChannel AcceptChannel (TimeSpan timeout)
{
ThrowIfDisposedOrNotOpen ();
return OnAcceptChannel (timeout);
}
public IAsyncResult BeginAcceptChannel (
AsyncCallback callback, object asyncState)
{
return BeginAcceptChannel (
timeouts.ReceiveTimeout, callback, asyncState);
}
public IAsyncResult BeginAcceptChannel (TimeSpan timeout,
AsyncCallback callback, object asyncState)
{
return OnBeginAcceptChannel (timeout, callback, asyncState);
}
public TChannel EndAcceptChannel (IAsyncResult result)
{
return OnEndAcceptChannel (result);
}
protected abstract TChannel OnAcceptChannel (TimeSpan timeout);
protected abstract IAsyncResult OnBeginAcceptChannel (TimeSpan timeout,
AsyncCallback callback, object asyncState);
protected abstract TChannel OnEndAcceptChannel (IAsyncResult result);
}
}

Some files were not shown because too many files have changed in this diff Show More