Веб-служба связи с клиентским сервером .NET NamedPipes - PullRequest
1 голос
/ 21 августа 2010

Я пытаюсь заставить клиент / сервер разговаривать взад и вперед в проекте, над которым я работаю. Кажется, работает нормально при разговоре между двумя службами Windows (пока). Но, кажется, возникают некоторые проблемы, когда я помещаю клиентскую сторону в веб-сервис. Сначала он работает нормально, пока множество запросов не попадают в него в быстрой последовательности, и в этот момент веб-служба зависает, а запросы веб-службы просто перестают работать (и соединитель сервера не получает никаких запросов). Однако, если я подключаюсь из другого тестового приложения, оно может нормально общаться со службой.

У кого-нибудь есть идея, почему это происходит?

Клиент:

protected T SendMessage<T>(ConnectorRequest request)
    {
        ConnectorResponse response = null;//default(T);
        BinaryFormatter formatter = new BinaryFormatter();
        try
        {
            using (NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", PIPE_NAME, PipeDirection.InOut))
            {
                //TODO: make this configurable
                pipeClient.Connect(Timeout);
                using (StreamWriter sw = new StreamWriter(pipeClient))
                {
                    sw.AutoFlush = true;
                    formatter.Serialize(pipeClient, request);
                    pipeClient.WaitForPipeDrain();
                    response = (ConnectorResponse)formatter.Deserialize(pipeClient);
                }
            }
        }
        catch (Exception ex)
        {
            logger.Error("response: " + response + "Exception thrown: " + ex);
        }
        return (T)response.Response;
    }

Сервер:

void ConnectorRun()
    {
        try
        {
            PipeSecurity ps = new PipeSecurity();
            ps.AddAccessRule(new PipeAccessRule("NETWORK SERVICE", PipeAccessRights.ReadWrite | PipeAccessRights.CreateNewInstance, AccessControlType.Allow));
            ps.AddAccessRule(new PipeAccessRule("Users", PipeAccessRights.ReadWrite | PipeAccessRights.CreateNewInstance, AccessControlType.Allow));
            ps.AddAccessRule(new PipeAccessRule("CREATOR OWNER", PipeAccessRights.FullControl, AccessControlType.Allow));
            ps.AddAccessRule(new PipeAccessRule("SYSTEM", PipeAccessRights.FullControl, AccessControlType.Allow));
            //ps.AddAccessRule(pa);

            _connectorIsRunning = true;
            //PipeSecurity security = new PipeSecurity(
            while (!_connectorStopRequested)
            {
                try
                {
                    using (NamedPipeServerStream pipeServer = new NamedPipeServerStream(PIPE_NAME, PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.None, 2048, 2048, ps))
                    {
                        pipeServer.WaitForConnection();
                        BinaryFormatter formatter = new BinaryFormatter();
                        ConnectorRequest request = (ConnectorRequest)formatter.Deserialize(pipeServer);
                        ConnectorResponse response = OnConnectorRequest(request);
                        formatter.Serialize(pipeServer, response);
                        pipeServer.WaitForPipeDrain();
                        pipeServer.Disconnect();
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex);
                }
            }
        }
        catch (Exception ex)
        {
            logger.Error(ex);
        }
        finally
        {
            _connectorIsRunning = false;
            OnConnectorServerStopped(this, new EventArgs());
        }
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...