internal ISingletonChannelListener OnGetSingletonMessageHandler(ServerSingletonPreambleConnectionReader serverSingletonPreambleReader)
        {
            Uri via = serverSingletonPreambleReader.Via;
            TChannelListener channelListener = GetChannelListener(via);

            if (channelListener != null)
            {
                if (channelListener is IChannelListener <IReplyChannel> )
                {
                    channelListener.RaiseMessageReceived();
                    return((ISingletonChannelListener)channelListener);
                }
                else
                {
                    serverSingletonPreambleReader.SendFault(FramingEncodingString.UnsupportedModeFault);
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new ProtocolException(SR.GetString(SR.FramingModeNotSupported, FramingMode.Singleton)));
                }
            }
            else
            {
                serverSingletonPreambleReader.SendFault(FramingEncodingString.EndpointNotFoundFault);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new EndpointNotFoundException(SR.GetString(SR.EndpointNotFound, via)));
            }
        }
 IAsyncResult BeginCompleteSingletonPreamble(
     ServerSingletonPreambleConnectionReader serverSingletonPreambleReader,
     ISingletonChannelListener singletonChannelListener,
     AsyncCallback callback, object state)
 {
     return(new CompleteSingletonPreambleAndDispatchRequestAsyncResult(serverSingletonPreambleReader, singletonChannelListener, this, callback, state));
 }
        void OnSingletonPreambleKnown(ServerSingletonPreambleConnectionReader serverSingletonPreambleReader)
        {
            lock (ThisLock)
            {
                if (isDisposed)
                {
                    return;
                }

                connectionReaders.Remove(serverSingletonPreambleReader);
            }

            if (onSingletonPreambleComplete == null)
            {
                onSingletonPreambleComplete = Fx.ThunkCallback(new AsyncCallback(OnSingletonPreambleComplete));
            }

            ISingletonChannelListener singletonChannelListener = singletonPreambleCallback(serverSingletonPreambleReader);

            Fx.Assert(singletonChannelListener != null,
                      "singletonPreambleCallback must return a listener or send a Fault/throw");

            // transfer ownership of the connection from the preamble reader to the message handler

            IAsyncResult result = BeginCompleteSingletonPreamble(serverSingletonPreambleReader, singletonChannelListener, onSingletonPreambleComplete, this);

            if (result.CompletedSynchronously)
            {
                EndCompleteSingletonPreamble(result);
            }
        }
 public ServerSingletonConnectionReader(ServerSingletonPreambleConnectionReader preambleReader, IConnection upgradedConnection, ConnectionDemuxer connectionDemuxer) : base(upgradedConnection, preambleReader.BufferOffset, preambleReader.BufferSize, preambleReader.Security, preambleReader.TransportSettings, preambleReader.Via)
 {
     this.decoder             = preambleReader.Decoder;
     this.contentType         = this.decoder.ContentType;
     this.connectionDemuxer   = connectionDemuxer;
     this.rawConnection       = preambleReader.RawConnection;
     this.channelBindingToken = preambleReader.ChannelBinding;
 }
 public ServerSingletonConnectionReader(ServerSingletonPreambleConnectionReader preambleReader, IConnection upgradedConnection, ConnectionDemuxer connectionDemuxer) : base(upgradedConnection, preambleReader.BufferOffset, preambleReader.BufferSize, preambleReader.Security, preambleReader.TransportSettings, preambleReader.Via)
 {
     this.decoder = preambleReader.Decoder;
     this.contentType = this.decoder.ContentType;
     this.connectionDemuxer = connectionDemuxer;
     this.rawConnection = preambleReader.RawConnection;
     this.channelBindingToken = preambleReader.ChannelBinding;
 }
示例#6
0
        private void OnSingletonPreambleKnown(ServerSingletonPreambleConnectionReader serverSingletonPreambleReader)
        {
            lock (this.ThisLock)
            {
                if (this.isDisposed)
                {
                    return;
                }
                this.connectionReaders.Remove(serverSingletonPreambleReader);
            }
            ISingletonChannelListener listener = this.singletonPreambleCallback(serverSingletonPreambleReader);
            TimeoutHelper             helper   = new TimeoutHelper(listener.ReceiveTimeout);
            IConnection    upgradedConnection  = serverSingletonPreambleReader.CompletePreamble(helper.RemainingTime());
            RequestContext requestContext      = new ServerSingletonConnectionReader(serverSingletonPreambleReader, upgradedConnection, this).ReceiveRequest(helper.RemainingTime());

            listener.ReceiveRequest(requestContext, serverSingletonPreambleReader.ConnectionDequeuedCallback, true);
        }
示例#7
0
        internal ISingletonChannelListener OnGetSingletonMessageHandler(ServerSingletonPreambleConnectionReader serverSingletonPreambleReader)
        {
            Uri via = serverSingletonPreambleReader.Via;
            TChannelListener channelListener = this.GetChannelListener(via);

            if (channelListener != null)
            {
                if (channelListener is IChannelListener <IReplyChannel> )
                {
                    channelListener.RaiseMessageReceived();
                    return((ISingletonChannelListener)channelListener);
                }
                serverSingletonPreambleReader.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/UnsupportedMode");
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("FramingModeNotSupported", new object[] { FramingMode.Singleton })));
            }
            serverSingletonPreambleReader.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/EndpointNotFound");
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new EndpointNotFoundException(System.ServiceModel.SR.GetString("EndpointNotFound", new object[] { via })));
        }
            public CompleteSingletonPreambleAndDispatchRequestAsyncResult(
                ServerSingletonPreambleConnectionReader serverSingletonPreambleReader,
                ISingletonChannelListener singletonChannelListener,
                ConnectionDemuxer demuxer,
                AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.serverSingletonPreambleReader = serverSingletonPreambleReader;
                this.singletonChannelListener      = singletonChannelListener;
                this.demuxer = demuxer;

                //if this throws, the calling code paths will abort the connection, so we only need to
                //call AbortConnection if BeginCompletePramble completes asynchronously.
                if (BeginCompletePreamble())
                {
                    Complete(true);
                }
            }
示例#9
0
        private void OnSingletonConnection(IConnection connection, Action connectionDequeuedCallback, long streamPosition, int offset, int size, TimeSpan timeout)
        {
            if (this.onSingletonPreambleKnown == null)
            {
                this.onSingletonPreambleKnown = new ServerSingletonPreambleCallback(this.OnSingletonPreambleKnown);
            }
            ServerSingletonPreambleConnectionReader item = new ServerSingletonPreambleConnectionReader(connection, connectionDequeuedCallback, streamPosition, offset, size, this.transportSettingsCallback, this.onConnectionClosed, this.onSingletonPreambleKnown);

            lock (this.ThisLock)
            {
                if (this.isDisposed)
                {
                    item.Dispose();
                    return;
                }
                this.connectionReaders.Add(item);
            }
            item.StartReading(this.viaDelegate, timeout);
        }
        void OnSingletonConnection(IConnection connection, Action connectionDequeuedCallback,
                                   long streamPosition, int offset, int size, TimeSpan timeout)
        {
            if (onSingletonPreambleKnown == null)
            {
                onSingletonPreambleKnown = OnSingletonPreambleKnown;
            }
            ServerSingletonPreambleConnectionReader singletonPreambleReader =
                new ServerSingletonPreambleConnectionReader(connection, connectionDequeuedCallback, streamPosition, offset, size,
                                                            transportSettingsCallback, onConnectionClosed, onSingletonPreambleKnown);

            lock (ThisLock)
            {
                if (isDisposed)
                {
                    singletonPreambleReader.Dispose();
                    return;
                }

                connectionReaders.Add(singletonPreambleReader);
            }
            singletonPreambleReader.StartReading(viaDelegate, timeout);
        }
 private void OnSingletonPreambleKnown(ServerSingletonPreambleConnectionReader serverSingletonPreambleReader)
 {
     lock (this.ThisLock)
     {
         if (this.isDisposed)
         {
             return;
         }
         this.connectionReaders.Remove(serverSingletonPreambleReader);
     }
     ISingletonChannelListener listener = this.singletonPreambleCallback(serverSingletonPreambleReader);
     TimeoutHelper helper = new TimeoutHelper(listener.ReceiveTimeout);
     IConnection upgradedConnection = serverSingletonPreambleReader.CompletePreamble(helper.RemainingTime());
     RequestContext requestContext = new ServerSingletonConnectionReader(serverSingletonPreambleReader, upgradedConnection, this).ReceiveRequest(helper.RemainingTime());
     listener.ReceiveRequest(requestContext, serverSingletonPreambleReader.ConnectionDequeuedCallback, true);
 }
 private void OnSingletonConnection(IConnection connection, Action connectionDequeuedCallback, long streamPosition, int offset, int size, TimeSpan timeout)
 {
     if (this.onSingletonPreambleKnown == null)
     {
         this.onSingletonPreambleKnown = new ServerSingletonPreambleCallback(this.OnSingletonPreambleKnown);
     }
     ServerSingletonPreambleConnectionReader item = new ServerSingletonPreambleConnectionReader(connection, connectionDequeuedCallback, streamPosition, offset, size, this.transportSettingsCallback, this.onConnectionClosed, this.onSingletonPreambleKnown);
     lock (this.ThisLock)
     {
         if (this.isDisposed)
         {
             item.Dispose();
             return;
         }
         this.connectionReaders.Add(item);
     }
     item.StartReading(this.viaDelegate, timeout);
 }
            public CompleteSingletonPreambleAndDispatchRequestAsyncResult(
                ServerSingletonPreambleConnectionReader serverSingletonPreambleReader,
                ISingletonChannelListener singletonChannelListener,
                ConnectionDemuxer demuxer,
                AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.serverSingletonPreambleReader = serverSingletonPreambleReader;
                this.singletonChannelListener = singletonChannelListener;
                this.demuxer = demuxer;

                //if this throws, the calling code paths will abort the connection, so we only need to 
                //call AbortConnection if BeginCompletePramble completes asynchronously.
                if (BeginCompletePreamble())
                {
                    Complete(true);
                }
            }
 IAsyncResult BeginCompleteSingletonPreamble(
     ServerSingletonPreambleConnectionReader serverSingletonPreambleReader, 
     ISingletonChannelListener singletonChannelListener,
     AsyncCallback callback, object state)
 {
     return new CompleteSingletonPreambleAndDispatchRequestAsyncResult(serverSingletonPreambleReader, singletonChannelListener, this, callback, state);
 }
        void OnSingletonPreambleKnown(ServerSingletonPreambleConnectionReader serverSingletonPreambleReader)
        {
            lock (ThisLock)
            {
                if (isDisposed)
                {
                    return;
                }

                connectionReaders.Remove(serverSingletonPreambleReader);
            }

            if (onSingletonPreambleComplete == null)
            {
                onSingletonPreambleComplete = Fx.ThunkCallback(new AsyncCallback(OnSingletonPreambleComplete));
            }

            ISingletonChannelListener singletonChannelListener = singletonPreambleCallback(serverSingletonPreambleReader);
            Fx.Assert(singletonChannelListener != null,
                "singletonPreambleCallback must return a listener or send a Fault/throw");

            // transfer ownership of the connection from the preamble reader to the message handler

            IAsyncResult result = BeginCompleteSingletonPreamble(serverSingletonPreambleReader, singletonChannelListener, onSingletonPreambleComplete, this);

            if (result.CompletedSynchronously)
            {
                EndCompleteSingletonPreamble(result);
            }
        }
        void OnSingletonConnection(IConnection connection, Action connectionDequeuedCallback,
            long streamPosition, int offset, int size, TimeSpan timeout)
        {
            if (onSingletonPreambleKnown == null)
            {
                onSingletonPreambleKnown = OnSingletonPreambleKnown;
            }
            ServerSingletonPreambleConnectionReader singletonPreambleReader =
                new ServerSingletonPreambleConnectionReader(connection, connectionDequeuedCallback, streamPosition, offset, size,
                transportSettingsCallback, onConnectionClosed, onSingletonPreambleKnown);

            lock (ThisLock)
            {
                if (isDisposed)
                {
                    singletonPreambleReader.Dispose();
                    return;
                }

                connectionReaders.Add(singletonPreambleReader);
            }
            singletonPreambleReader.StartReading(viaDelegate, timeout);
        }