コード例 #1
0
        private void ReadAsyncUnixMessage(object data)
        {
            ITransportHeaders       transportHeader;
            IClientChannelSinkStack clientChannelSinkStack = (IClientChannelSinkStack)data;
            UnixConnection          unixConnection         = (UnixConnection)clientChannelSinkStack.Pop(this);

            try
            {
                if (UnixMessageIO.ReceiveMessageStatus(unixConnection.Stream, unixConnection.Buffer) != MessageStatus.MethodMessage)
                {
                    throw new RemotingException("Unknown response message from server");
                }
                Stream stream = UnixMessageIO.ReceiveMessageStream(unixConnection.Stream, out transportHeader, unixConnection.Buffer);
                unixConnection.Release();
                unixConnection = null;
                clientChannelSinkStack.AsyncProcessResponse(transportHeader, stream);
            }
            catch
            {
                if (unixConnection != null)
                {
                    unixConnection.Release();
                }
                throw;
            }
        }
コード例 #2
0
ファイル: httpclientchannel.cs プロジェクト: ydunk/masters
        } // AsyncProcessRequest

        private void OnHttpMessageReturn(IAsyncResult ar)
        {
            IClientChannelSinkStack sinkStack = (IClientChannelSinkStack)ar.AsyncState;

            HttpWebResponse response = null;

            HttpWebRequest httpWebRequest = (HttpWebRequest)sinkStack.Pop(this);

            try
            {
                response = (HttpWebResponse)httpWebRequest.EndGetResponse(ar);
            }
            catch (WebException webException)
            {
                ProcessResponseException(webException, out response);
            }

            // process incoming response
            ITransportHeaders responseHeaders;
            Stream            responseStream;

            ReceiveAndProcess(response, out responseHeaders, out responseStream);

            // call down the sink chain
            sinkStack.AsyncProcessResponse(responseHeaders, responseStream);
        } // OnHttpMessageReturn
コード例 #3
0
        void AsyncProcessResponseCallback(IAsyncResult ar)
        {
            IClientChannelSinkStack sinkStack = (IClientChannelSinkStack)ar.AsyncState;
            HttpWebRequest          request   = (HttpWebRequest)sinkStack.Pop(this);

            WebResponse response;

            try {
                response = request.EndGetResponse(ar);
            } catch (WebException ex) {
                response = ex.Response;
                //only error 500 is handled by the remoting stack
                HttpWebResponse httpResponse = response as HttpWebResponse;
                if (httpResponse == null || httpResponse.StatusCode != HttpStatusCode.InternalServerError)
                {
                    sinkStack.DispatchException(ex);
                    return;
                }
            }

            //this is only valid after the response is fetched
            SetConnectionLimit(request);

            using (response) {
                Stream            responseStream  = response.GetResponseStream();
                ITransportHeaders responseHeaders = GetHeaders(response);
                sinkStack.AsyncProcessResponse(responseHeaders, responseStream);
            }
        }
コード例 #4
0
        private void ReadAsyncTcpMessage(object data)
        {
            // This method is called by a new thread to asynchronously
            // read the response to a request

            // The stack was provided as state data in QueueUserWorkItem
            IClientChannelSinkStack stack = (IClientChannelSinkStack)data;

            // The first sink in the stack is this sink. Pop it and
            // get the status data, which is the TcpConnection used to send
            // the request
            TcpConnection connection = (TcpConnection)stack.Pop(this);

            try
            {
                ITransportHeaders responseHeaders;

                // Read the response, blocking if necessary
                MessageStatus status = TcpMessageIO.ReceiveMessageStatus(connection.Stream, connection.Buffer);

                if (status != MessageStatus.MethodMessage)
                {
                    throw new RemotingException("Unknown response message from server");
                }

                Stream responseStream = TcpMessageIO.ReceiveMessageStream(connection.Stream, out responseHeaders, connection.Buffer);

                // Free the connection, so it can be reused
                connection.Release();
                connection = null;

                // Ok, proceed with the other sinks
                stack.AsyncProcessResponse(responseHeaders, responseStream);
            }
            catch
            {
                if (connection != null)
                {
                    connection.Release();
                }
                throw;
            }
        }