public MessageSizeDetectionEncoderFactory(
     MessageEncoderFactory innerFactory)
 {
     this.innerFactory = innerFactory;
     this.encoder = new MessageSizeDetectionEncoder(
         innerFactory.Encoder);
 }
        //The GZip encoder wraps an inner encoder
        //We require a factory to be passed in that will create this inner encoder
        public GZipMessageEncoderFactory(MessageEncoderFactory messageEncoderFactory)
        {
            if (messageEncoderFactory == null)
                throw new ArgumentNullException("messageEncoderFactory", "A valid message encoder factory must be passed to the GZipEncoder");
            encoder = new GZipMessageEncoder(messageEncoderFactory.Encoder);

        }
示例#3
0
    public MockChannelBase(ChannelManagerBase manager, MessageEncoderFactory encoderFactory, EndpointAddress address)
    : base(manager)
    {
        _address = address;
        _manager = manager;
        _encoder = encoderFactory.CreateSessionEncoder();

        OpenAsyncResult = new MockAsyncResult();
        CloseAsyncResult = new MockAsyncResult();

        GetEndpointPropertyOverride = DefaultGetEndpointProperty;

        // CommunicationObject overrides
        DefaultCloseTimeoutOverride = DefaultDefaultCloseTimeout;
        DefaultOpenTimeoutOverride = DefaultDefaultOpenTimeout;

        OnAbortOverride = DefaultOnAbort;
        OnOpenOverride = DefaultOnOpen;
        OnCloseOverride = DefaultOnClose;

        OnBeginOpenOverride = DefaultOnBeginOpen;
        OnEndOpenOverride = DefaultOnEndOpen;

        OnBeginCloseOverride = DefaultOnBeginClose;
        OnEndCloseOverride = DefaultOnEndClose;

        // All the virtuals
        OnOpeningOverride = DefaultOnOpening;
        OnOpenedOverride = DefaultOnOpened;
        OnClosingOverride = DefaultOnClosing;
        OnClosedOverride = DefaultOnClosed;
        OnFaultedOverride = DefaultOnFaulted;
    }
 public FileReplyChannel(BufferManager bufferManager, MessageEncoderFactory encoderFactory, EndpointAddress address,
     FileReplyChannelListener parent)
     : base(bufferManager, encoderFactory, address, parent, parent.MaxReceivedMessageSize)
 {
     this.localAddress = address;
     this.readLock = new object();
 }
示例#5
0
        protected TransportChannelFactory(TransportBindingElement bindingElement, BindingContext context,
                                          MessageEncoderFactory defaultMessageEncoderFactory)
            : base(context.Binding)
        {
            this.manualAddressing       = bindingElement.ManualAddressing;
            this.maxBufferPoolSize      = bindingElement.MaxBufferPoolSize;
            this.maxReceivedMessageSize = bindingElement.MaxReceivedMessageSize;

            Collection <MessageEncodingBindingElement> messageEncoderBindingElements
                = context.BindingParameters.FindAll <MessageEncodingBindingElement>();

            if (messageEncoderBindingElements.Count > 1)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MultipleMebesInParameters)));
            }
            else if (messageEncoderBindingElements.Count == 1)
            {
                this.messageEncoderFactory = messageEncoderBindingElements[0].CreateMessageEncoderFactory();
                context.BindingParameters.Remove <MessageEncodingBindingElement>();
            }
            else
            {
                this.messageEncoderFactory = defaultMessageEncoderFactory;
            }

            if (null != this.messageEncoderFactory)
            {
                this.messageVersion = this.messageEncoderFactory.MessageVersion;
            }
            else
            {
                this.messageVersion = MessageVersion.None;
            }
        }
示例#6
0
        protected TransportChannelFactory(TransportBindingElement bindingElement, BindingContext context, System.ServiceModel.Channels.MessageEncoderFactory defaultMessageEncoderFactory) : base(context.Binding)
        {
            this.manualAddressing       = bindingElement.ManualAddressing;
            this.maxBufferPoolSize      = bindingElement.MaxBufferPoolSize;
            this.maxReceivedMessageSize = bindingElement.MaxReceivedMessageSize;
            Collection <MessageEncodingBindingElement> messageEncodingBindingElements = context.BindingParameters.FindAll <MessageEncodingBindingElement>();

            if (messageEncodingBindingElements.Count > 1)
            {
                throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(Microsoft.ServiceBus.SR.GetString(Resources.MultipleMebesInParameters, new object[0])));
            }
            if (messageEncodingBindingElements.Count != 1)
            {
                this.messageEncoderFactory = defaultMessageEncoderFactory;
            }
            else
            {
                this.messageEncoderFactory = messageEncodingBindingElements[0].CreateMessageEncoderFactory();
                context.BindingParameters.Remove <MessageEncodingBindingElement>();
            }
            if (this.messageEncoderFactory == null)
            {
                this.messageVersion = System.ServiceModel.Channels.MessageVersion.None;
                return;
            }
            this.messageVersion = this.messageEncoderFactory.MessageVersion;
        }
 public MessageBusReplySessionChannel(
     BufferManager bufferManager, MessageEncoderFactory encoderFactory, ChannelManagerBase parent,
     EndpointAddress localAddress,
     IBus bus)
     : base(bufferManager, encoderFactory, parent, localAddress, bus)
 {
 }
示例#8
0
        public MessageBusInputChannel(
            BufferManager bufferManager, MessageEncoderFactory encoder, ChannelManagerBase parent,
            EndpointAddress localAddress,
            IBus bus)
            : base(bufferManager, encoder, parent)
        {
            _localAddress = localAddress;
            _bus = bus;
            _aLock = new object();

            _tryReceiveDelegate = (TimeSpan timeout, out Message message) =>
            {
                message = null;
                try
                {
                    var requestMessage = _bus.Receive(true, null);
                    if (requestMessage != null)
                    {
                        message = GetWcfMessageFromString(requestMessage.Content);
                        OnAfterTryReceive(requestMessage);
                    }
                }
                catch (Exception ex)
                {
                    throw new CommunicationException(ex.Message, ex);
                }
                return true;
            };

            _receiveDelegate = (TimeSpan timeout) =>
            {
                var requestMessage = _bus.Receive(false, ChannelID);
                return GetWcfMessageFromString(requestMessage.Content);
            };
        }
示例#9
0
        internal UdpChannelFactory(UdpTransportBindingElement transportBindingElement, BindingContext context)
            : base(context.Binding)
        {
            Fx.Assert(transportBindingElement != null, "transportBindingElement can't be null");
            Fx.Assert(context != null, "binding context can't be null");
            Fx.Assert(typeof(TChannel) == typeof(IOutputChannel) || typeof(TChannel) == typeof(IDuplexChannel), "this channel factory only supports IOutputChannel and IDuplexChannel");

            this.udpTransportBindingElement = transportBindingElement;

            // We should only throw this exception if the user specified realistic MaxReceivedMessageSize less than or equal to max message size over UDP.
            // If the user specified something bigger like Long.MaxValue, we shouldn't stop them.
            if (this.udpTransportBindingElement.MaxReceivedMessageSize <= UdpConstants.MaxMessageSizeOverIPv4 &&
                this.udpTransportBindingElement.SocketReceiveBufferSize < this.udpTransportBindingElement.MaxReceivedMessageSize)
            {
                throw FxTrace.Exception.ArgumentOutOfRange("SocketReceiveBufferSize", this.udpTransportBindingElement.SocketReceiveBufferSize,
                                                           SR.Property1LessThanOrEqualToProperty2("MaxReceivedMessageSize", this.udpTransportBindingElement.MaxReceivedMessageSize,
                                                                                                  "SocketReceiveBufferSize", this.udpTransportBindingElement.SocketReceiveBufferSize));
            }

            this.messageEncoderFactory = UdpUtility.GetEncoder(context);

            bool retransmissionEnabled = this.udpTransportBindingElement.RetransmissionSettings.Enabled;
            //duplicated detection doesn't apply to IOutputChannel, so don't throw if we are only sending
            bool duplicateDetectionEnabled = this.udpTransportBindingElement.DuplicateMessageHistoryLength > 0 ? typeof(TChannel) != typeof(IOutputChannel) : false;

            UdpUtility.ValidateDuplicateDetectionAndRetransmittionSupport(this.messageEncoderFactory, retransmissionEnabled, duplicateDetectionEnabled);

            int maxBufferSize = (int)Math.Min(transportBindingElement.MaxReceivedMessageSize, UdpConstants.MaxMessageSizeOverIPv4);

            this.BufferManager = BufferManager.CreateBufferManager(transportBindingElement.MaxBufferPoolSize, maxBufferSize);
        }
示例#10
0
        public XeroMessageEncoderFactory(MessageEncoderFactory innerEncoderFactory)
        {
            if (innerEncoderFactory == null)
                throw new ArgumentNullException("innerEncoderFactory");

            _encoder = new XeroMessageEncoder(innerEncoderFactory.Encoder);
        }
示例#11
0
        /// <summary>
        /// SerialChannel Base
        /// </summary>
        /// <param name="bufferManager">
        /// Buffer manager created by factory and listener</param>
        /// <param name="encoderFactory">
        /// Referece to encoder factory as returned by encoder element</param>
        /// <param name="address">Remote address</param>
        /// <param name="portNumber">COM port number</param>
        /// <param name="parent">reference to factory/listener</param>
        /// <param name="maxReceivedMessageSize">
        /// Some settings for transport channel</param>
        public SerialChannelBase(BufferManager bufferManager, 
            MessageEncoderFactory encoderFactory, 
            EndpointAddress address,
            string portNumber,
            ChannelManagerBase parent,
            long maxReceivedMessageSize)
            : base(parent)
        {
            this.address = address;
            this.bufferManager = bufferManager;
            this.encoder = encoderFactory.CreateSessionEncoder();
            this.maxReceivedMessageSize = maxReceivedMessageSize;

            this.portNumber = portNumber;

            // Create port
            serialPort = new SerialPort();

            // Set the appropriate properties.
            serialPort.PortName = this.portNumber;
            //TODO: Read these settings from configuration file
            serialPort.BaudRate = 9600;
            serialPort.Parity = Parity.None;
            serialPort.DataBits = 8;
            serialPort.StopBits = StopBits.One;
            serialPort.Handshake = Handshake.None;

            // Set the read/write timeouts
            serialPort.ReadTimeout = 500;
            serialPort.WriteTimeout = 500;
        }
 public FileRequestChannel(BufferManager bufferManager, MessageEncoderFactory encoderFactory, EndpointAddress address,
     FileRequestChannelFactory parent, Uri via)
     : base(bufferManager, encoderFactory, address, parent, parent.MaxReceivedMessageSize)
 {
     this.via = via;
     this.writeLock = new object();
 }
 public MessageBusRequestSessionChannel(
     BufferManager bufferManager, MessageEncoderFactory encoder, ChannelManagerBase parent, 
     EndpointAddress remoteAddress, Uri via,
     IBus bus)
     : base(bufferManager, encoder, parent, remoteAddress, via, bus)
 {
     _session = new MessageBusOutputSession((new UniqueId()).ToString());
 }
 protected MsmqChannelListenerBase(MsmqBindingElementBase bindingElement,
                                   BindingContext context,
                                   MsmqReceiveParameters receiveParameters,
                                   MessageEncoderFactory messageEncoderFactory)
     : base(bindingElement, context, messageEncoderFactory)
 {
     this.receiveParameters = receiveParameters;
 }
示例#15
0
        protected MessageBusChannelBase(BufferManager bufferManager, MessageEncoderFactory encoder, ChannelManagerBase parent)
            : base(parent)
        {
            _id = Guid.NewGuid();

            _bufferManager = bufferManager;
            _encoder = encoder.CreateSessionEncoder();
        }
 protected MsmqChannelListenerBase(MsmqBindingElementBase bindingElement,
                                   BindingContext context,
                                   MsmqReceiveParameters receiveParameters,
                                   MessageEncoderFactory messageEncoderFactory)
     : base(bindingElement, context, messageEncoderFactory)
 {
     this.receiveParameters = receiveParameters;
 }
 public static Message Dequeue(this IRabbitMQReader rabbitMessageQueueReader, RabbitMQTaskQueueBinding binding, MessageEncoderFactory messageEncoderFactory, TimeSpan timeout, CancellationToken cancelToken)
 {
     ulong deliveryTag;
     var timeoutTimer = TimeoutTimer.StartNew(timeout);
     var msg = rabbitMessageQueueReader.Dequeue(binding, messageEncoderFactory, timeoutTimer.RemainingTime, cancelToken, out deliveryTag);
     rabbitMessageQueueReader.AcknowledgeMessage(deliveryTag, timeoutTimer.RemainingTime, cancelToken);
     return msg;
 }
示例#18
0
 public WcfHandler(Type serviceType, MessageEncoderFactory messageEncoderFactory)
 {
     this.ServiceType = serviceType;
     this.MessageEncoderFactory = messageEncoderFactory;
     this.Methods = new Dictionary<string, MethodInfo>();
     this.MessageFormatters = new Dictionary<string, IDispatchMessageFormatter>();
     this.OperationInvokers = new Dictionary<string, IOperationInvoker>();
 }
 public AzureTableReplyChannel(BufferManager bufferManager, MessageEncoderFactory encoderFactory, EndpointAddress address,
    AzureTableReplyChannelListener parent, CloudTableClient cloudTableClient, string tableName, string partitionKey,
     TimeSpan idleSleep, TimeSpan activeSleep)
     : base(bufferManager, encoderFactory, address, parent, parent.MaxReceivedMessageSize, cloudTableClient, tableName, 
     partitionKey, idleSleep, activeSleep)
 {
     this.localAddress = address;
 }
 public AzureTableRequestChannel(BufferManager bufferManager, MessageEncoderFactory encoderFactory, EndpointAddress address,
    AzureTableRequestChannelFactory parent, Uri via, CloudTableClient cloudTableClient, string tableName, string partitionKey,
     TimeSpan idleSleep, TimeSpan activeSleep)
     : base(bufferManager, encoderFactory, address, parent, parent.MaxReceivedMessageSize, cloudTableClient, tableName, 
     partitionKey, idleSleep, activeSleep)
 {
     this.via = via;
     this.writeLock = new object();
 }
示例#21
0
    public MockRequestChannel(ChannelManagerBase manager, MessageEncoderFactory encoderFactory, EndpointAddress address, Uri via)
            : base(manager, encoderFactory, address)
    {
        this._via = via;

        RequestOverride = DefaultRequest;
        BeginRequestOverride = DefaultBeginRequest;
        EndRequestOverride = DefaultEndRequest;
    }
 internal SMEVTextMessageEncoderFactory(string mediaType, string charSet, MessageVersion version, MessageEncoderFactory messageFactory, string actor)
 {
     this.version = version;
     this.mediaType = mediaType;
     this.charSet = charSet;
     this.actor = actor;
     this.innerMessageFactory = messageFactory;
     this.encoder = (MessageEncoder)new SMEVTextMessageEncoder(this);
 }
 public FileChannelBase(BufferManager bufferManager, MessageEncoderFactory encoderFactory, EndpointAddress address, ChannelManagerBase parent,
  long maxReceivedMessageSize)
     : base(parent)
 {
     this.address = address;
     this.bufferManager = bufferManager;
     this.encoder = encoderFactory.CreateSessionEncoder();
     this.maxReceivedMessageSize = maxReceivedMessageSize;
 }
 public MessageBusDuplexSessionChannel(
     BufferManager bufferManager, MessageEncoderFactory encoder, ChannelManagerBase parent,
     EndpointAddress remoteAddress, Uri via,
     IBus bus,
     bool isClient)
     : base(bufferManager, encoder, remoteAddress, parent, via, bus, isClient)
 {
     _session = new MessageBusDuplexSession((new UniqueId()).ToString());
 }
示例#25
0
 public MessageBusRequestChannel(
     BufferManager bufferManager, MessageEncoderFactory encoder, ChannelManagerBase parent,
     EndpointAddress remoteAddress, Uri via, IBus bus)
     : base(bufferManager, encoder, parent)
 {
     _via = via;
     _remoteAddress = remoteAddress;
     _bus = bus;
     _aLock = new object();
 }
示例#26
0
 public MessageBusOutputChannel(
     BufferManager bufferManager, MessageEncoderFactory encoder, ChannelManagerBase parent,
     EndpointAddress remoteAddress,
     Uri via, IBus bus)
     : base(bufferManager, encoder, parent)
 {
     _bus = bus;
     _via = via;
     _remoteAddress = remoteAddress;
 }
 internal SMEVTextMessageEncoderFactory(string mediaType, string charSet, MessageVersion version, MessageEncoderFactory messageFactory, string logPath, string senderActor)
 {
     _version = version;
     _mediaType = mediaType;
     _charSet = charSet;
     SenderActor = senderActor;
     _innerMessageFactory = messageFactory;
     LogPath = logPath;
     _encoder = new SMEVTextMessageEncoder(this);
 }
 public FileTransportChannelBase(BufferManager bufferManager,
         MessageEncoderFactory messageEncoderFactory, EndpointAddress address,
         ChannelManagerBase parent, bool streamed, long maxReceivedMessageSize)
     : base(parent)
 {
     this.bufferManager = bufferManager;
     this.messageEncoder = messageEncoderFactory.CreateSessionEncoder();
     this.remoteAddress = address;
     this.streamed = streamed;
     this.maxReceivedMessageSize = maxReceivedMessageSize;
 }
        //The GZip encoder wraps an inner encoder
        //We require a factory to be passed in that will create this inner encoder
        public CompressMessageEncoderFactory(MessageEncoderFactory messageEncoderFactory,
            CompressionAlgorithm compressionAlgorithm)
        {
            if (messageEncoderFactory == null)
                throw new ArgumentNullException("messageEncoderFactory",
                                                "A valid message encoder factory must be passed to the CompressionEncoder");

            _encoder = new MyCompressionMessageEncoder(messageEncoderFactory.Encoder, compressionAlgorithm);
            _compressionAlgorithm = compressionAlgorithm;
            _innerFactory = messageEncoderFactory;
        }
 protected WseTcpDuplexSessionChannel(
     MessageEncoderFactory messageEncoderFactory, BufferManager bufferManager,
     EndpointAddress remoteAddress, EndpointAddress localAddress, Uri via, ChannelManagerBase channelManager)
     : base(channelManager)
 {
     this.remoteAddress = remoteAddress;
     this.localAddress = localAddress;
     this.via = via;
     this.session = new TcpDuplexSession(this);
     this.encoder = messageEncoderFactory.CreateSessionEncoder();
     this.bufferManager = bufferManager;
 }
 public RabbitMQTaskQueueRequestContext(Message requestMessage, RabbitMQTaskQueueBinding binding, EndpointAddress localAddress, MessageEncoderFactory msgEncoderFactory, BufferManager bufferManager, IRabbitMQWriter queueWriter, ulong deliveryTag, IRabbitMQReader queueReader, IDisposable readerHandle)
 {
     _opMgr = new ConcurrentOperationManager(GetType().FullName);
     _queueReader = queueReader;
     _readerHandle = readerHandle;
     _deliveryTag = deliveryTag;
     _bufferMgr = bufferManager;
     _msgEncoderFactory = msgEncoderFactory;
     _replyToAddress = localAddress;
     _binding = binding;
     _rqMsg = requestMessage;
     _reply = Reply;
     _queueWriter = queueWriter;
 }
 public AzureTableChannelBase(BufferManager bufferManager, MessageEncoderFactory encoderFactory, EndpointAddress address, ChannelManagerBase parent, 
     long maxReceivedMessageSize, CloudTableClient cloudTableClient, string tableName, string partitionKey, TimeSpan idleSleep, TimeSpan activeSleep)
     : base(parent)
 {
     this.address = address;
     this.bufferManager = bufferManager;
     this.encoder = encoderFactory.CreateSessionEncoder();
     this.maxReceivedMessageSize = maxReceivedMessageSize;
     this.partitionKey = partitionKey;
     this.channelClosed = false;
     this.cloudTableClient = cloudTableClient;
     this.tableName = tableName;
     this.idleSleep = idleSleep;
     this.activeSleep = activeSleep;
 }
        internal UdpChannelListener(UdpTransportBindingElement udpTransportBindingElement, BindingContext context)
            : base(context.Binding)
        {
            Fx.Assert(udpTransportBindingElement != null, "udpTransportBindingElement can't be null");
            Fx.Assert(context != null, "BindingContext parameter can't be null");

            this.udpTransportBindingElement = udpTransportBindingElement;
            this.cleanedUp = 0;

            this.duplicateDetector = null;

            if (udpTransportBindingElement.DuplicateMessageHistoryLength > 0)
            {
                this.duplicateDetector = new DuplicateMessageDetector(udpTransportBindingElement.DuplicateMessageHistoryLength);
            }

            this.onChannelClosed = new EventHandler(OnChannelClosed);

            // We should only throw this exception if the user specified realistic MaxReceivedMessageSize less than or equal to max message size over UDP.
            // If the user specified something bigger like Long.MaxValue, we shouldn't stop them.
            if (this.udpTransportBindingElement.MaxReceivedMessageSize <= UdpConstants.MaxMessageSizeOverIPv4 &&
                this.udpTransportBindingElement.SocketReceiveBufferSize < this.udpTransportBindingElement.MaxReceivedMessageSize)
            {
                throw FxTrace.Exception.ArgumentOutOfRange("SocketReceiveBufferSize", this.udpTransportBindingElement.SocketReceiveBufferSize,
                                                           SR.Property1LessThanOrEqualToProperty2("MaxReceivedMessageSize", this.udpTransportBindingElement.MaxReceivedMessageSize,
                                                                                                  "SocketReceiveBufferSize", this.udpTransportBindingElement.SocketReceiveBufferSize));
            }


            int maxBufferSize = (int)Math.Min(udpTransportBindingElement.MaxReceivedMessageSize, UdpConstants.MaxMessageSizeOverIPv4);

            this.bufferManager = BufferManager.CreateBufferManager(udpTransportBindingElement.MaxBufferPoolSize, maxBufferSize);

            this.messageEncoderFactory = UdpUtility.GetEncoder(context);

            UdpUtility.ValidateDuplicateDetectionAndRetransmittionSupport(this.messageEncoderFactory, this.udpTransportBindingElement.RetransmissionSettings.Enabled, this.udpTransportBindingElement.DuplicateMessageHistoryLength > 0);

            InitUri(context);

            //Note: because we are binding the sockets in InitSockets, we can start receiving data immediately.
            //If there is a delay between the Building of the listener and the call to Open, stale data could build up
            //inside the Winsock buffer.  We have decided that making sure the port is updated correctly in the listen uri
            //(e.g. in the ListenUriMode.Unique case) before leaving the build step is more important than the
            //potential for stale data.
            InitSockets(context.ListenUriMode == ListenUriMode.Unique);

            Fx.Assert(!this.listenUri.IsDefaultPort, "Listen Uri's port should never be the default port: " + this.listenUri);
        }
示例#34
0
        public static MessageEncoderFactory GetEncoder(BindingContext context)
        {
            MessageEncodingBindingElement messageEncoderBindingElement = context.BindingParameters.Remove <MessageEncodingBindingElement>();
            MessageEncoderFactory         factory = null;

            if (messageEncoderBindingElement != null)
            {
                factory = messageEncoderBindingElement.CreateMessageEncoderFactory();
            }
            else
            {
                factory = UdpConstants.Defaults.MessageEncoderFactory;
            }

            return(factory);
        }
 public static Message Dequeue(this IRabbitMQReader rabbitMessageQueueReader, RabbitMQTaskQueueBinding binding, MessageEncoderFactory messageEncoderFactory, TimeSpan timeout, CancellationToken cancelToken, out ulong deliveryTag)
 {
     var timeoutTimer = TimeoutTimer.StartNew(timeout);
     var msg = rabbitMessageQueueReader.Dequeue(timeoutTimer.RemainingTime, cancelToken);
     deliveryTag = msg.DeliveryTag;
     Message result;
     try
     {
         result = messageEncoderFactory.Encoder.ReadMessage(msg.Body, (int)binding.MaxReceivedMessageSize);
     }
     catch
     {
         rabbitMessageQueueReader.RejectMessage(msg.DeliveryTag, timeoutTimer.RemainingTime, cancelToken);
         throw;
     }
     return result;
 }
示例#36
0
        public static void ValidateDuplicateDetectionAndRetransmittionSupport(MessageEncoderFactory messageEncoderFactory, bool retransmissionEnabled, bool duplicateDetectionEnabled)
        {
            Fx.Assert(messageEncoderFactory != null, "messageEncoderFactory shouldn't be null");

            MessageVersion encoderMessageVersion = messageEncoderFactory.MessageVersion;

            if (encoderMessageVersion.Addressing == AddressingVersion.None)
            {
                if (retransmissionEnabled)
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(SR.TransportRequiresAddressingOnEncoderForRetransmission(encoderMessageVersion, "RetransmissionSettings", typeof(UdpTransportBindingElement).Name)));
                }

                if (duplicateDetectionEnabled)
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(SR.TransportRequiresAddressingOnEncoderForDuplicateDetection(encoderMessageVersion, "DuplicateMessageHistoryLength", typeof(UdpTransportBindingElement).Name)));
                }
            }
        }
        public DefaultWebSocketConnectionHandler(string subProtocol, string currentVersion, MessageVersion messageVersion, MessageEncoderFactory encoderFactory, TransferMode transferMode)
        {
            this.subProtocol = subProtocol;
            this.currentVersion = currentVersion;
            this.checkVersionFunc = new Func<string, bool>(this.CheckVersion);

            if (messageVersion != MessageVersion.None)
            {
                this.needToCheckContentType = true;
                this.encoder = encoderFactory.CreateSessionEncoder();
                this.checkContentTypeFunc = new Func<string, bool>(this.CheckContentType);

                if (encoderFactory is BinaryMessageEncoderFactory)
                {
                    this.needToCheckTransferMode = true;
                    this.transferMode = transferMode.ToString();
                    this.checkTransferModeFunc = new Func<string, bool>(this.CheckTransferMode);
                }
            }
        }
        public DefaultWebSocketConnectionHandler(string subProtocol, string currentVersion, MessageVersion messageVersion, MessageEncoderFactory encoderFactory, TransferMode transferMode)
        {
            this.subProtocol      = subProtocol;
            this.currentVersion   = currentVersion;
            this.checkVersionFunc = new Func <string, bool>(this.CheckVersion);

            if (messageVersion != MessageVersion.None)
            {
                this.needToCheckContentType = true;
                this.encoder = encoderFactory.CreateSessionEncoder();
                this.checkContentTypeFunc = new Func <string, bool>(this.CheckContentType);

                if (encoderFactory is BinaryMessageEncoderFactory)
                {
                    this.needToCheckTransferMode = true;
                    this.transferMode            = transferMode.ToString();
                    this.checkTransferModeFunc   = new Func <string, bool>(this.CheckTransferMode);
                }
            }
        }
示例#39
0
 protected TransportChannelListener(TransportBindingElement bindingElement, BindingContext context, System.ServiceModel.Channels.MessageEncoderFactory defaultMessageEncoderFactory) : this(bindingElement, context, defaultMessageEncoderFactory, HostNameComparisonMode.Exact)
 {
 }
示例#40
0
        protected TransportChannelListener(TransportBindingElement bindingElement, BindingContext context, System.ServiceModel.Channels.MessageEncoderFactory defaultMessageEncoderFactory, HostNameComparisonMode hostNameComparisonMode) : base(context.Binding)
        {
            Microsoft.ServiceBus.Channels.HostNameComparisonModeHelper.Validate(hostNameComparisonMode);
            this.hostNameComparisonMode = hostNameComparisonMode;
            this.manualAddressing       = bindingElement.ManualAddressing;
            this.maxBufferPoolSize      = bindingElement.MaxBufferPoolSize;
            this.maxReceivedMessageSize = bindingElement.MaxReceivedMessageSize;
            Collection <MessageEncodingBindingElement> messageEncodingBindingElements = context.BindingParameters.FindAll <MessageEncodingBindingElement>();

            if (messageEncodingBindingElements.Count > 1)
            {
                throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(Microsoft.ServiceBus.SR.GetString(Resources.MultipleMebesInParameters, new object[0])));
            }
            if (messageEncodingBindingElements.Count != 1)
            {
                this.messageEncoderFactory = defaultMessageEncoderFactory;
            }
            else
            {
                this.messageEncoderFactory = messageEncodingBindingElements[0].CreateMessageEncoderFactory();
                context.BindingParameters.Remove <MessageEncodingBindingElement>();
            }
            if (this.messageEncoderFactory == null)
            {
                this.messageVersion = System.ServiceModel.Channels.MessageVersion.None;
            }
            else
            {
                this.messageVersion = this.messageEncoderFactory.MessageVersion;
            }
            ServiceSecurityAuditBehavior serviceSecurityAuditBehavior = context.BindingParameters.Find <ServiceSecurityAuditBehavior>();

            if (serviceSecurityAuditBehavior == null)
            {
                this.auditBehavior = new ServiceSecurityAuditBehavior();
            }
            else
            {
                this.auditBehavior = (ServiceSecurityAuditBehavior)InvokeHelper.InvokeInstanceMethod(typeof(ServiceSecurityAuditBehavior), serviceSecurityAuditBehavior, "Clone", new object[0]);
            }
            if (context.ListenUriMode == ListenUriMode.Unique && context.ListenUriBaseAddress == null)
            {
                UriBuilder uriBuilder = new UriBuilder(this.Scheme, Microsoft.ServiceBus.Channels.DnsCache.MachineName)
                {
                    Path = this.GeneratedAddressPrefix
                };
                context.ListenUriBaseAddress = uriBuilder.Uri;
            }
            Microsoft.ServiceBus.Channels.UriSchemeKeyedCollection.ValidateBaseAddress(context.ListenUriBaseAddress, "baseAddress");
            if (context.ListenUriBaseAddress.Scheme != this.Scheme && !context.ListenUriBaseAddress.Scheme.Equals("sbwss") && string.Compare(context.ListenUriBaseAddress.Scheme, this.Scheme, StringComparison.OrdinalIgnoreCase) != 0)
            {
                ExceptionUtility exceptionUtility = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                string           invalidUriScheme = Resources.InvalidUriScheme;
                object[]         scheme           = new object[] { context.ListenUriBaseAddress.Scheme, this.Scheme };
                throw exceptionUtility.ThrowHelperArgument("context.ListenUriBaseAddress", Microsoft.ServiceBus.SR.GetString(invalidUriScheme, scheme));
            }
            Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.DebugAssert(context.ListenUriRelativeAddress != null, "");
            if (context.ListenUriMode != ListenUriMode.Explicit)
            {
                string listenUriRelativeAddress = context.ListenUriRelativeAddress;
                if (listenUriRelativeAddress.Length > 0 && !listenUriRelativeAddress.EndsWith("/", StringComparison.Ordinal))
                {
                    listenUriRelativeAddress = string.Concat(listenUriRelativeAddress, "/");
                }
                System.Uri listenUriBaseAddress = context.ListenUriBaseAddress;
                Guid       guid = Guid.NewGuid();
                this.SetUri(listenUriBaseAddress, string.Concat(listenUriRelativeAddress, guid.ToString()));
            }
            else
            {
                this.SetUri(context.ListenUriBaseAddress, context.ListenUriRelativeAddress);
            }
            this.transportManagerContainer = new Microsoft.ServiceBus.Channels.TransportManagerContainer(this);
        }
 protected TransportChannelListener(TransportBindingElement bindingElement, BindingContext context,
                                    MessageEncoderFactory defaultMessageEncoderFactory)
     : this(bindingElement, context, defaultMessageEncoderFactory, TransportDefaults.HostNameComparisonMode)
 {
 }
        protected TransportChannelListener(TransportBindingElement bindingElement, BindingContext context,
                                           MessageEncoderFactory defaultMessageEncoderFactory, HostNameComparisonMode hostNameComparisonMode)
            : base(context.Binding)
        {
            HostNameComparisonModeHelper.Validate(hostNameComparisonMode);
            this.hostNameComparisonMode = hostNameComparisonMode;
            this.manualAddressing       = bindingElement.ManualAddressing;
            this.maxBufferPoolSize      = bindingElement.MaxBufferPoolSize;
            this.maxReceivedMessageSize = bindingElement.MaxReceivedMessageSize;

            Collection <MessageEncodingBindingElement> messageEncoderBindingElements
                = context.BindingParameters.FindAll <MessageEncodingBindingElement>();

            if (messageEncoderBindingElements.Count > 1)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MultipleMebesInParameters)));
            }
            else if (messageEncoderBindingElements.Count == 1)
            {
                this.messageEncoderFactory = messageEncoderBindingElements[0].CreateMessageEncoderFactory();
                context.BindingParameters.Remove <MessageEncodingBindingElement>();
            }
            else
            {
                this.messageEncoderFactory = defaultMessageEncoderFactory;
            }

            if (null != this.messageEncoderFactory)
            {
                this.messageVersion = this.messageEncoderFactory.MessageVersion;
            }
            else
            {
                this.messageVersion = MessageVersion.None;
            }

            ServiceSecurityAuditBehavior auditBehavior = context.BindingParameters.Find <ServiceSecurityAuditBehavior>();

            if (auditBehavior != null)
            {
                this.auditBehavior = auditBehavior.Clone();
            }
            else
            {
                this.auditBehavior = new ServiceSecurityAuditBehavior();
            }

            if ((context.ListenUriMode == ListenUriMode.Unique) && (context.ListenUriBaseAddress == null))
            {
                UriBuilder uriBuilder = new UriBuilder(this.Scheme, DnsCache.MachineName);
                uriBuilder.Path = this.GeneratedAddressPrefix;
                context.ListenUriBaseAddress = uriBuilder.Uri;
            }

            UriSchemeKeyedCollection.ValidateBaseAddress(context.ListenUriBaseAddress, "baseAddress");
            if (context.ListenUriBaseAddress.Scheme != this.Scheme)
            {
                // URI schemes are case-insensitive, so try a case insensitive compare now
                if (string.Compare(context.ListenUriBaseAddress.Scheme, this.Scheme, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(
                              "context.ListenUriBaseAddress",
                              SR.GetString(SR.InvalidUriScheme, context.ListenUriBaseAddress.Scheme, this.Scheme));
                }
            }

            Fx.Assert(context.ListenUriRelativeAddress != null, ""); // validated by BindingContext
            if (context.ListenUriMode == ListenUriMode.Explicit)
            {
                this.SetUri(context.ListenUriBaseAddress, context.ListenUriRelativeAddress);
            }
            else // ListenUriMode.Unique:
            {
                string relativeAddress = context.ListenUriRelativeAddress;
                if (relativeAddress.Length > 0 && !relativeAddress.EndsWith("/", StringComparison.Ordinal))
                {
                    relativeAddress += "/";
                }

                this.SetUri(context.ListenUriBaseAddress, relativeAddress + Guid.NewGuid().ToString());
            }

            this.transportManagerContainer = new TransportManagerContainer(this);
        }
示例#43
0
 internal MsmqInputChannelListenerBase(MsmqBindingElementBase bindingElement, BindingContext context, MsmqReceiveParameters receiveParameters, MessageEncoderFactory encoderFactory) : base(bindingElement, context, receiveParameters, encoderFactory)
 {
     this.acceptor = new InputQueueChannelAcceptor <IInputChannel>(this);
 }
示例#44
0
        protected MsmqChannelFactoryBase(MsmqBindingElementBase bindingElement, BindingContext context, MessageEncoderFactory encoderFactory)
            : base(bindingElement, context)
        {
            this.addressTranslator     = bindingElement.AddressTranslator;
            this.customDeadLetterQueue = bindingElement.CustomDeadLetterQueue;
            this.durable               = bindingElement.Durable;
            this.deadLetterQueue       = bindingElement.DeadLetterQueue;
            this.exactlyOnce           = bindingElement.ExactlyOnce;
            this.msmqTransportSecurity = new MsmqTransportSecurity(bindingElement.MsmqTransportSecurity);
            this.timeToLive            = bindingElement.TimeToLive;
            this.useMsmqTracing        = bindingElement.UseMsmqTracing;
            this.useSourceJournal      = bindingElement.UseSourceJournal;

            if (this.MsmqTransportSecurity.MsmqAuthenticationMode == MsmqAuthenticationMode.Certificate)
            {
                InitializeSecurityTokenManager(context);
            }

            if (null != this.customDeadLetterQueue)
            {
                this.deadLetterQueuePathName = MsmqUri.DeadLetterQueueAddressTranslator.UriToFormatName(this.customDeadLetterQueue);
            }
        }
示例#45
0
        internal HttpChannelFactory(HttpTransportBindingElement bindingElement, BindingContext context)
            : base(bindingElement, context, HttpTransportDefaults.GetDefaultMessageEncoderFactory())
        {
            // validate setting interactions
            if (bindingElement.TransferMode == TransferMode.Buffered)
            {
                if (bindingElement.MaxReceivedMessageSize > int.MaxValue)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new ArgumentOutOfRangeException("bindingElement.MaxReceivedMessageSize",
                                                              SR.MaxReceivedMessageSizeMustBeInIntegerRange));
                }

                if (bindingElement.MaxBufferSize != bindingElement.MaxReceivedMessageSize)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("bindingElement",
                                                                                 SR.MaxBufferSizeMustMatchMaxReceivedMessageSize);
                }
            }
            else
            {
                if (bindingElement.MaxBufferSize > bindingElement.MaxReceivedMessageSize)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("bindingElement",
                                                                                 SR.MaxBufferSizeMustNotExceedMaxReceivedMessageSize);
                }
            }

            if (TransferModeHelper.IsRequestStreamed(bindingElement.TransferMode) &&
                bindingElement.AuthenticationScheme != AuthenticationSchemes.Anonymous)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("bindingElement",
                                                                             SR.HttpAuthDoesNotSupportRequestStreaming);
            }

            _allowCookies = bindingElement.AllowCookies;

            if (_allowCookies)
            {
                _httpCookieContainerManager = new HttpCookieContainerManager();
            }

            if (!bindingElement.AuthenticationScheme.IsSingleton())
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("value", SR.Format(SR.HttpRequiresSingleAuthScheme,
                                                                                                bindingElement.AuthenticationScheme));
            }
            _authenticationScheme = bindingElement.AuthenticationScheme;
            _maxBufferSize        = bindingElement.MaxBufferSize;
            _transferMode         = bindingElement.TransferMode;
            _useDefaultWebProxy   = bindingElement.UseDefaultWebProxy;

            _channelCredentials   = context.BindingParameters.Find <SecurityCredentialsManager>();
            _securityCapabilities = bindingElement.GetProperty <ISecurityCapabilities>(context);

            _webSocketSettings = WebSocketHelper.GetRuntimeWebSocketSettings(bindingElement.WebSocketSettings);
            int webSocketBufferSize = WebSocketHelper.ComputeClientBufferSize(MaxReceivedMessageSize);

            _bufferPool               = new ConnectionBufferPool(webSocketBufferSize);
            _clientWebSocketFactory   = ClientWebSocketFactory.GetFactory();
            _webSocketSoapContentType = new Lazy <string>(() => MessageEncoderFactory.CreateSessionEncoder().ContentType, LazyThreadSafetyMode.ExecutionAndPublication);
        }