public void ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, out ITransportHeaders responseHeaders, out Stream responseStream) { responseHeaders = null; responseStream = null; requestHeaders[CommonTransportKeys.RequestUri] = ((IMethodCallMessage)msg).Uri; // connect NamedPipeClient client = new NamedPipeClient(pipeName); NamedPipeSocket socket = client.Connect(); IpcTransport t = new IpcTransport(socket); t.Write(requestHeaders, requestStream); t.Read(out responseHeaders, out responseStream); t.Close(); }
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 headers, Stream stream) { headers[CommonTransportKeys.RequestUri] = ((IMethodCallMessage)msg).Uri; // connect NamedPipeClient client = new NamedPipeClient(pipeName); NamedPipeSocket socket = client.Connect(); IpcTransport t = new IpcTransport(socket); t.Write(headers, stream); // schedule an async call if (!RemotingServices.IsOneWay(((IMethodCallMessage)msg).MethodBase)) { new AsyncResponse(AsyncHandler).BeginInvoke(sinkStack, t, null, null); } }
void ProcessClient(object state) { try { NamedPipeSocket socket = (NamedPipeSocket) state; ITransportHeaders requestHeaders; Stream requestStream; IpcTransport t = new IpcTransport(socket); t.Read(out requestHeaders, out requestStream); // parse the RequestUri string objectUri; string uri = (string) requestHeaders[CommonTransportKeys.RequestUri]; IpcChannelHelper.Parse(uri, out objectUri); if (objectUri == null) objectUri = uri; requestHeaders[CommonTransportKeys.RequestUri] = objectUri; ServerChannelSinkStack stack = new ServerChannelSinkStack(); stack.Push(this, null); IMessage responseMsg; ITransportHeaders responseHeaders; Stream responseStream; requestHeaders["__CustomErrorsEnabled"] = false; if (impersonate) { // TODO: Impersonate might throw exceptions. What to do with them? socket.Impersonate(); } ServerProcessing op = nextSink.ProcessMessage( stack, null, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream ); if (impersonate) { NamedPipeSocket.RevertToSelf(); } switch (op) { case ServerProcessing.Complete: stack.Pop(this); // send the response headers and the response data to the client t.Write(responseHeaders, responseStream); break; case ServerProcessing.Async: stack.StoreAndDispatch(nextSink, null); break; case ServerProcessing.OneWay: break; } } catch (Exception) { // Console.WriteLine(ex); } }
void ProcessClient(object state) { try { NamedPipeSocket socket = (NamedPipeSocket)state; ITransportHeaders requestHeaders; Stream requestStream; IpcTransport t = new IpcTransport(socket); t.Read(out requestHeaders, out requestStream); // parse the RequestUri string objectUri; string uri = (string)requestHeaders[CommonTransportKeys.RequestUri]; IpcChannelHelper.Parse(uri, out objectUri); if (objectUri == null) { objectUri = uri; } requestHeaders[CommonTransportKeys.RequestUri] = objectUri; ServerChannelSinkStack stack = new ServerChannelSinkStack(); stack.Push(this, null); IMessage responseMsg; ITransportHeaders responseHeaders; Stream responseStream; requestHeaders["__CustomErrorsEnabled"] = false; if (impersonate) { // TODO: Impersonate might throw exceptions. What to do with them? socket.Impersonate(); } ServerProcessing op = nextSink.ProcessMessage( stack, null, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream ); if (impersonate) { NamedPipeSocket.RevertToSelf(); } switch (op) { case ServerProcessing.Complete: stack.Pop(this); // send the response headers and the response data to the client t.Write(responseHeaders, responseStream); break; case ServerProcessing.Async: stack.StoreAndDispatch(nextSink, null); break; case ServerProcessing.OneWay: break; } } catch (Exception) { // Console.WriteLine(ex); } }