private void AsyncFinishedCallback(IAsyncResult ar) { IClientChannelSinkStack sinkStack = null; try { ITransportHeaders responseHeaders = null; Stream responseStream = null; sinkStack = ((AsyncMessageDelegate)((AsyncResult)ar).AsyncDelegate).EndInvoke(out responseHeaders, out responseStream, ar); sinkStack.AsyncProcessResponse(responseHeaders, responseStream); } catch (Exception ex) { try { if (sinkStack != null) { sinkStack.DispatchException(ex); } return; } catch (Exception ex2) { Trace.WriteLine(ex2); return; } } }
} // StartRequest // This should only be done when the send fails. internal void RetryOrDispatchException(Exception e) { bool bRetry = false; try { if (_retryCount > 0) { _retryCount--; if (RequestStream.CanSeek) { RequestStream.Position = _initialStreamPosition; StartRequest(); bRetry = true; } } } catch { } if (!bRetry) { RequestStream.Close(); SinkStack.DispatchException(e); } } // DispatchExceptionOrRetry
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); } }
} // AsyncProcessRequest private void AsyncFinishedCallback(IAsyncResult ar) { IClientChannelSinkStack sinkStack = null; try { AsyncMessageDelegate d = (AsyncMessageDelegate)(((AsyncResult)ar).AsyncDelegate); ITransportHeaders responseHeaders; Stream responseStream; sinkStack = d.EndInvoke(out responseHeaders, out responseStream, ar); // call down the sink chain sinkStack.AsyncProcessResponse(responseHeaders, responseStream); } catch (Exception e) { try { if (sinkStack != null) { sinkStack.DispatchException(e); } } catch { // Fatal Error.. ignore } } }
/// <summary>call back to call, when the async response has arrived.</summary> private void AsyncResponseArrived(IClientChannelSinkStack sinkStack, GiopClientConnection con, Stream responseStream, Exception resultException) { ITransportHeaders responseHeaders = new TransportHeaders(); responseHeaders[GiopClientConnectionDesc.CLIENT_TR_HEADER_KEY] = con.Desc; // add to response headers // forward the response if ((resultException == null) && (responseStream != null)) { #if DEBUG OutputHelper.LogStream(responseStream); #endif responseStream.Seek(0, SeekOrigin.Begin); // assure stream is read from beginning in formatter sinkStack.AsyncProcessResponse(responseHeaders, responseStream); } else { Exception toThrow = resultException; if (toThrow == null) { toThrow = new omg.org.CORBA.INTERNAL(79, omg.org.CORBA.CompletionStatus.Completed_MayBe); } sinkStack.DispatchException(toThrow); } }
private void AsyncFinishedCallback(IAsyncResult ar) { IClientChannelSinkStack stack = null; try { ITransportHeaders headers; Stream stream; stack = ((AsyncMessageDelegate)((AsyncResult)ar).AsyncDelegate).EndInvoke(out headers, out stream, ar); stack.AsyncProcessResponse(headers, stream); } catch (Exception exception) { try { if (stack != null) { stack.DispatchException(exception); } } catch { } } }
private void ReceiveCallback(object state) { TcpClientSocketHandler handler = null; IClientChannelSinkStack dataArrivedCallbackState = null; try { handler = (TcpClientSocketHandler)state; dataArrivedCallbackState = (IClientChannelSinkStack)handler.DataArrivedCallbackState; ITransportHeaders headers = handler.ReadHeaders(); Stream responseStream = handler.GetResponseStream(); dataArrivedCallbackState.AsyncProcessResponse(headers, responseStream); } catch (Exception exception) { try { if (dataArrivedCallbackState != null) { dataArrivedCallbackState.DispatchException(exception); } } catch { } } }
public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders requestHeaders, Stream requestStream) { // add message Uri to headers var mcm = (IMethodCallMessage)msg; requestHeaders[CommonTransportKeys.RequestUri] = mcm.Uri; // send data (FIXME: 1) add reliability, 2) handle exceptions) var transport = new UdpTransport(UdpClient); transport.Write(requestHeaders, requestStream, ServerEndpoint); // if the call is not one-way, schedule an async call if (!RemotingServices.IsOneWay(mcm.MethodBase)) { ThreadPool.QueueUserWorkItem((s) => { try { ITransportHeaders responseHeaders; Stream responseStream; IPEndPoint remote; transport.Read(out responseHeaders, out responseStream, out remote); sinkStack.AsyncProcessResponse(responseHeaders, responseStream); } catch (Exception ex) { sinkStack.DispatchException(ex); } }); } }
} // SendRequestWithRetry private void ReceiveCallback(Object state) { TcpClientSocketHandler clientSocket = null; IClientChannelSinkStack sinkStack = null; try { clientSocket = (TcpClientSocketHandler)state; sinkStack = (IClientChannelSinkStack)clientSocket.DataArrivedCallbackState; ITransportHeaders responseHeaders = clientSocket.ReadHeaders(); Stream responseStream = clientSocket.GetResponseStream(); // call down the sink chain sinkStack.AsyncProcessResponse(responseHeaders, responseStream); } catch (Exception e) { try { if (sinkStack != null) { sinkStack.DispatchException(e); } } catch (Exception) { // Fatal Error.. ignore } } // The client socket will be returned to the cache // when the response stream is closed. } // ReceiveCallback
public void ProcessResponse(IAsyncResult ar) { Connection connection; Exception exception; Message reply = Manager.EndReadMessage(out connection, out exception, ar); IClientChannelSinkStack sinkStack = (IClientChannelSinkStack)ar.AsyncState; if (exception != null) { sinkStack.DispatchException(exception); } sinkStack.AsyncProcessResponse(reply.Headers, reply.MessageBody); }
void AsyncHandler(IClientChannelSinkStack sinkStack, IpcTransport transport) { try { // get the response headers and the response stream from the server ITransportHeaders responseHeaders; Stream responseStream; transport.Read(out responseHeaders, out responseStream); transport.Close(); sinkStack.AsyncProcessResponse(responseHeaders, responseStream); } catch (Exception ex) { sinkStack.DispatchException(ex); } }
private void ReceiveCallback(Object state) { //Console.WriteLine("ReceiveCallback TID {0}", Thread.CurrentThread.GetHashCode()); PipeConnectionCookie cookie = (PipeConnectionCookie)state; PipeConnection _pipe = cookie.pipe; IClientChannelSinkStack sinkStack = cookie.sinkStack; try { // Read response // _pipe.BeginReadMessage(); ITransportHeaders responseHeaders = _pipe.ReadHeaders(); responseHeaders["__CustomErrorsEnabled"] = false; Stream responseStream = _pipe.ReadStream(); _pipe.EndReadMessage(); if (_pipeConnectionPool != null) { _pipeConnectionPool.ReturnToPool(_pipe); } _pipe = null; sinkStack.AsyncProcessResponse(responseHeaders, responseStream); } catch (Exception e) { try { if (sinkStack != null) { sinkStack.DispatchException(e); } } catch (Exception) { // Fatal Error.. ignore } } } // ReceiveCallback
void AsyncHandler(IClientChannelSinkStack sinkStack, IpcTransport transport) { try { // get the response headers and the response stream from the server ITransportHeaders responseHeaders; Stream responseStream; transport.Read(out responseHeaders, out responseStream); transport.Close(); sinkStack.AsyncProcessResponse(responseHeaders, responseStream); } catch (Exception ex) { sinkStack.DispatchException(ex); } }
public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders requestHeaders, Stream requestStream) { // add message Uri to headers var mcm = (IMethodCallMessage)msg; requestHeaders[CommonTransportKeys.RequestUri] = mcm.Uri; // send data (FIXME: 1) add reliability, 2) handle exceptions) var transport = new UdpTransport(UdpClient); transport.Write(requestHeaders, requestStream, ServerEndpoint); // if the call is not one-way, schedule an async call if (!RemotingServices.IsOneWay(mcm.MethodBase)) { ThreadPool.QueueUserWorkItem((s) => { try { ITransportHeaders responseHeaders; Stream responseStream; IPEndPoint remote; transport.Read(out responseHeaders, out responseStream, out remote); sinkStack.AsyncProcessResponse(responseHeaders, responseStream); } catch (Exception ex) { sinkStack.DispatchException(ex); } }); } }
/// <summary>call back to call, when the async response has arrived.</summary> private void AsyncResponseArrived(IClientChannelSinkStack sinkStack, GiopClientConnection con, Stream responseStream, Exception resultException) { ITransportHeaders responseHeaders = new TransportHeaders(); responseHeaders[GiopClientConnectionDesc.CLIENT_TR_HEADER_KEY]= con.Desc; // add to response headers // forward the response if ((resultException == null) && (responseStream != null)) { #if DEBUG OutputHelper.LogStream(responseStream); #endif responseStream.Seek(0, SeekOrigin.Begin); // assure stream is read from beginning in formatter sinkStack.AsyncProcessResponse(responseHeaders, responseStream); } else { Exception toThrow = resultException; if (toThrow == null) { toThrow = new omg.org.CORBA.INTERNAL(79, omg.org.CORBA.CompletionStatus.Completed_MayBe); } sinkStack.DispatchException(toThrow); } }