Exemple #1
0
        internal Client RaiseClientConnected(HostConnection connection, int protocolNumber)
        {
            Require.NotNull(connection, "connection");

            lock (_syncRoot)
            {
                Debug.Assert(_connections.ContainsKey(connection) && _connections[connection] == null);

                object client = null;

                try
                {
                    client = CreateServiceCore(protocolNumber);
                }
                catch (Exception ex)
                {
                    Log.Error("Failed to create service", ex);
                }

                if (client != null)
                {
                    var hostClient = new Client(client, ServiceAssembly, Service);

                    _connections[connection] = hostClient;
                    _clients[client] = connection;

                    return hostClient;
                }
                else
                {
                    return null;
                }
            }
        }
        protected override void Dispose(bool disposing)
        {
            lock (SyncRoot)
            {
                if (!_disposed && disposing)
                {
                    // Cancel all outstanding requests.

                    var disconnectException = new ProtoChannelException("Channel disconnected");

                    _messageManager.SetError(disconnectException);
                    _receiveStreamManager.SetError(disconnectException);

                    if (Client != null)
                    {
                        Client.Dispose();
                        Client = null;
                    }

                    _disposed = true;
                }
            }

            base.Dispose(disposing);
        }