Example #1
0
 public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders headers, Stream stream)
 {
     CompressSinkHelper.SetClientSupportCompressFlag(headers);
     stream = CompressSinkHelper.CompressStream(headers, stream);
     sinkStack.Push(this, null);
     _next.AsyncProcessRequest(sinkStack, msg, headers, stream);
 }
Example #2
0
        /// <summary>Requests asynchronous processing of a method call on the current sink.</summary>
        /// <param name="sinkStack">A stack of channel sinks.</param>
        /// <param name="msg">The message to process.</param>
        /// <param name="headers">The headers to send to the server.</param>
        /// <param name="stream">The stream headed to the transport sink.</param>
        public void AsyncProcessRequest(
            IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders headers, Stream stream)
        {
            AsyncProcessingState state = null;
            Stream encryptedStream     = null;
            Guid   id;

            lock (_transactionLock)            // could be a big lock... probably a faster way, but for now suffices
            {
                // Establish connection information with the server; the roundtrip will hopefully
                // only be done once, so we ensure that we have the necessary information.
                id = EnsureIDAndProvider(msg, headers);

                // Protect ourselves a bit.  If the asynchronous call fails because the server forgot about
                // us, we'll be in a bit of a fix.  We'll need the current arguments as we'll need
                // to retry the request synchronously.  Store them into a state object and use
                // that as the state when pushing ourself onto the stack.  That way, AsyncProcessResponse
                // have access to it.
                state = new AsyncProcessingState(msg, headers, ref stream, id);

                // Send encrypted message by encrypting the stream
                encryptedStream = SetupEncryptedMessage(headers, stream);
            }

            // Push ourselves onto the stack with the necessary state and forward on to the next sink
            sinkStack.Push(this, state);
            _next.AsyncProcessRequest(sinkStack, msg, headers, encryptedStream);
        }
Example #3
0
        private void AsyncProcessMessageOnce(IMessage msg,
                                             Ior target, IMessageSink replySink)
        {
            IIorProfile selectedProfile;
            uint        reqId;

            try {
                // allocate (reserve) connection
                GiopClientConnectionDesc conDesc = AllocateConnection(msg, target, out selectedProfile, out reqId);
                SimpleGiopMsg.SetMessageAsyncRequest(msg); // mark message as async, needed for portable interceptors
                ITransportHeaders requestHeaders;
                Stream            requestStream;
                SerialiseRequest(msg, selectedProfile, conDesc, reqId,
                                 out requestHeaders, out requestStream);
                // pass the serialised GIOP-request to the first stream handling sink
                // this sink is the last sink in the message handling sink chain, therefore the reply sink chain of all the previous message handling
                // sink is passed to the ClientChannelSinkStack, which will inform this chain of the received reply
                ClientChannelSinkStack clientSinkStack = new ClientChannelSinkStack(replySink);
                AsyncProcessingData    asyncData       = new AsyncProcessingData(msg, conDesc);
                clientSinkStack.Push(this, asyncData); // push the formatter onto the sink stack, to get the chance to handle the incoming reply stream
                // forward the message to the next sink
                m_nextSink.AsyncProcessRequest(clientSinkStack, msg, requestHeaders, requestStream);
                // for oneway messages, release the connections for future use
                if ((msg is IMethodCallMessage) && GiopMessageHandler.IsOneWayCall((IMethodCallMessage)msg))
                {
                    m_conManager.RequestOnConnectionCompleted(msg);  // release the connection, because this interaction is complete
                }
            } catch {
                // release the connection, if something went wrong during connection allocation and send
                m_conManager.RequestOnConnectionCompleted(msg); // release the connection, because this interaction is complete
                throw;
            }
        }
        public IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)
        {
            IMethodCallMessage mcm = (IMethodCallMessage)msg;
            IMessage           retMsg;

            try
            {
                // serialize message
                ITransportHeaders headers;
                Stream            requestStream;
                SerializeMessage(msg, out headers, out requestStream);

                // process message
                ClientChannelSinkStack sinkStack = new ClientChannelSinkStack(replySink);
                sinkStack.Push(this, msg);
                _nextSink.AsyncProcessRequest(sinkStack, msg, headers, requestStream);
            }
            catch (Exception e)
            {
                retMsg = new ReturnMessage(e, mcm);
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(retMsg);
                }
            }

            return(null);
        } // AsyncProcessMessage
        /// <summary>
        /// Processes an asynchronous request.
        /// </summary>
        /// <param name="sinkStack">Channel sink stack</param>
        /// <param name="msg">Message to processed</param>
        /// <param name="headers">Transport headers</param>
        /// <param name="stream">Request stream</param>
        public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders headers, Stream stream)
        {
            stream = CreateEnvelope(stream, headers);

            sinkStack.Push(this, null);
            _nextSink.AsyncProcessRequest(sinkStack, msg, headers, stream);
        }
 public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg,
                                 ITransportHeaders headers, Stream stream)
 {
     // перенаправляем вызов следующему приемнику в стеке
     sinkStack.Push(this, null);
     _nextSink.AsyncProcessRequest(sinkStack, msg, headers, stream);
 }
Example #7
0
        public IMessageCtrl AsyncProcessMessage(IMessage msg,
                                                IMessageSink replySink)
        {
            ITransportHeaders transportHeaders = new TransportHeaders();
            Stream            stream           = _nextInChain.GetRequestStream(msg, transportHeaders);

            if (stream == null)
            {
                stream = new MemoryStream();
            }

            _binaryCore.Serializer.Serialize(stream, msg, null);
            if (stream is MemoryStream)
            {
                stream.Position = 0;
            }

            ClientChannelSinkStack stack = new ClientChannelSinkStack(replySink);

            stack.Push(this, msg);

            _nextInChain.AsyncProcessRequest(stack, msg, transportHeaders, stream);

            // FIXME: No idea about how to implement IMessageCtrl
            return(null);
        }
Example #8
0
        public IMessageCtrl AsyncProcessMessage(IMessage requestMsg, IMessageSink replySink)
        {
            // parameters validation
            IMethodCallMessage methodCall = (requestMsg as IMethodCallMessage);

            if (methodCall == null)
            {
                throw new NotSupportedException();
            }

            try
            {
                // serialize request
                ITransportHeaders requestHeaders;
                Stream            requestStream;
                SerializeRequest(methodCall, out requestHeaders, out requestStream);

                // create sink stack for async request processing
                ClientChannelSinkStack sinkStack = new ClientChannelSinkStack(replySink);
                sinkStack.Push(this, requestMsg);                       // save request message as state

                // call next sink to dispatch method call
                _nextSink.AsyncProcessRequest(sinkStack, requestMsg, requestHeaders, requestStream);
            }
            catch (Exception ex)
            {
                if (replySink != null)
                {
                    // process exception synchronously
                    replySink.SyncProcessMessage(new ReturnMessage(ex, methodCall));
                }
            }

            return(null);
        }
Example #9
0
        /// <summary>
        /// Verarbeitet eine Anfragenachricht asynchron.
        /// </summary>
        /// <param name="sinkStack">Senkenstapel</param>
        /// <param name="msg">Remoting-Nachricht</param>
        /// <param name="headers">Anfrage-Header-Auflistung</param>
        /// <param name="stream">Anfrage-Datenstrom</param>
        public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders headers, Stream stream)
        {
            // Asynchroner Verarbeitungsstatus
            AsyncProcessingState state = null;

            // Verschlüsselter Datenstrom
            Stream encryptedStream = null;

            // Eindeutige Kennung der Sicherheitstransaktion
            Guid _secureTransactionID;

            lock (_lockObject)
            {
                // Sicherheitstransaktion starten
                _secureTransactionID = StartSecureTransaction(msg, headers);

                // Asynchronen Verarbeitungsstatus erzeugen
                state = new AsyncProcessingState(msg, headers, ref stream, _secureTransactionID);

                // Nachricht verschlüsseln
                encryptedStream = EncryptMessage(headers, stream);
            }
            // Aktuelle Senke auf den Senkenstapel legen (Damit ggf. die Verarbeitung der Antwort später asynchron aufgerufen werden kann)
            sinkStack.Push(this, state);

            // Nächste Kanalsenke aufrufen
            _next.AsyncProcessRequest(sinkStack, msg, headers, encryptedStream);
        }
Example #10
0
        public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders headers, Stream stream)
        {
            Stream compStream;

            Stream origStream = stream;
            long   origPos    = stream.Position;

            if ((checkedCompress && serverCanCompress) || (!checkedCompress && assumeCompress))
            {
                headers[CompressionHelper.CompressKey] = CompressionHelper.CompressedFlag;
                compStream = CompressionHelper.CompressStream(stream);
                sinkStack.Push(this, new RequestState(origStream, origPos, true, msg, headers));
            }
            else
            {
                headers[CompressionHelper.CompressKey] = CompressionHelper.CompressRequest;
                compStream = stream;
                sinkStack.Push(this, null);
            }

            try {
                _next.AsyncProcessRequest(sinkStack, msg, headers, compStream);
            }
            catch (Exception) {
            }
        }
Example #11
0
        public IMessageCtrl AsyncProcessMessage(IMessage msg,
                                                IMessageSink replySink)
        {
            ITransportHeaders transportHeaders = new TransportHeaders();

            transportHeaders[CommonTransportKeys.RequestUri] = ((IMethodCallMessage)msg).Uri;
            transportHeaders["Content-Type"] = "application/octet-stream";

            Stream stream = _nextInChain.GetRequestStream(msg, transportHeaders);

            if (stream == null)
            {
                stream = new MemoryStream();
            }

            _binaryCore.Serializer.Serialize(stream, msg, null);
            if (stream is MemoryStream)
            {
                stream.Position = 0;
            }

            ClientChannelSinkStack stack = new ClientChannelSinkStack(replySink);

            stack.Push(this, msg);

            _nextInChain.AsyncProcessRequest(stack, msg, transportHeaders, stream);

            // FIXME: No idea about how to implement IMessageCtrl
            return(null);
        }
        /// <summary>
        /// Requests asynchronous processing of a method call on the current sink.
        /// </summary>
        /// <param name="sinkStack">A stack of channel sinks that called this sink.</param>
        /// <param name="msg">The message to process.</param>
        /// <param name="headers">The headers to add to the outgoing message heading to the server.</param>
        /// <param name="stream">The stream headed to the transport sink.</param>
        /// <exception cref="T:System.Security.SecurityException">The immediate caller does not have infrastructure permission. </exception>
        public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders headers, Stream stream)
        {
            // Push this onto the sink stack.
            sinkStack.Push(this, null);

            // Send the request to the client.
            _next.AsyncProcessRequest(sinkStack, msg, headers, stream);
        }
        public void AsyncProcessRequest(IClientChannelSinkStack sinkStack,
                                        IMessage msg,
                                        ITransportHeaders headers,
                                        Stream stream)
        {
            SetSinkProperties(msg);

            // don't push on the sinkstack because this sink doesn’t need
            // to handle any replies!

            _nextSink.AsyncProcessRequest(sinkStack, msg, headers, stream);
        }
        public void AsyncProcessRequest(IClientChannelSinkStack sinkStack,
                                        IMessage msg,
                                        ITransportHeaders headers,
                                        Stream stream)
        {
            // generate a compressed stream using NZipLib
            stream = CompressionHelper.getCompressedStreamCopy(stream);

            // push onto stack and forward the request
            sinkStack.Push(this, null);
            _nextSink.AsyncProcessRequest(sinkStack, msg, headers, stream);
        }
Example #15
0
        public void AsyncProcessRequest(IClientChannelSinkStack sinkStack,
                                        IMessage msg,
                                        ITransportHeaders headers,
                                        Stream stream)
        {
            headers["X-Compress"] = "yes";

            stream = CompressionHelper.GetCompressedStreamCopy(stream);

            // push onto stack and forward the request

            sinkStack.Push(this, null);
            _nextSink.AsyncProcessRequest(sinkStack, msg, headers, stream);
        }
Example #16
0
        public void AsyncProcessRequest(
            IClientChannelSinkStack stack,
            IMessage msg,
            ITransportHeaders headers,
            Stream stream
            )
        {
            #region Add hash to stream header
            string hash = HashHelper.GetHash(ref stream);
            headers[HashHelper.C_HASH_ITEM] = hash;
            //Debug.WriteLine("Client Side : client request stream hash is " + hash);
            #endregion

            stack.Push(this, null);
            _nextSink.AsyncProcessRequest(stack, msg, headers, stream);
        }
Example #17
0
        public IMessageCtrl AsyncProcessMessage(IMessage msg,
                                                IMessageSink replySink)
        {
            Stream reqStream;

            FormatMessage(msg, out reqStream);

            TransportHeaders       reqHeaders = new TransportHeaders();
            ClientChannelSinkStack stack      = new ClientChannelSinkStack(replySink);

            stack.Push(this, msg);

            _next.AsyncProcessRequest(stack, msg, reqHeaders, reqStream);

            return(null);
        }
Example #18
0
        public void AsyncProcessRequest(IClientChannelSinkStack sinkStack,
                                        IMessage msg,
                                        ITransportHeaders headers,
                                        Stream stream)
        {
            byte[] IV;

            stream = EncryptionHelper.ProcessOutboundStream(stream,
                                                            _encryptionAlgorithm, _encryptionKey, out IV);

            headers["X-Encrypt"]   = "yes";
            headers["X-EncryptIV"] = Convert.ToBase64String(IV);

            // push onto stack and forward the request
            sinkStack.Push(this, null);
            _nextSink.AsyncProcessRequest(sinkStack, msg, headers, stream);
        }
Example #19
0
        public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders headers, Stream stream)
        {
            AsyncProcessingState state = null;
            Stream encryptedStream     = null;
            Guid   id;

            lock (_transactionLock)
            {
                id = EnsureIDAndProvider(msg, headers);

                state = new AsyncProcessingState(msg, headers, ref stream, id);

                encryptedStream = SetupEncryptedMessage(headers, stream, null);
            }

            sinkStack.Push(this, state);
            _next.AsyncProcessRequest(sinkStack, msg, headers, encryptedStream);
        }
        public void AsyncProcessRequest(IClientChannelSinkStack sinkStack,
                                        IMessage msg, ITransportHeaders headers, Stream stream)
        {
            RemotingResult result = cache.GetPreviousResults(msg, headers, true);

            if (result == null)
            {
                _asyncMessage = msg;
                _asyncHeaders = headers;
                sinkStack.Push(this, null);
                _nextSink.AsyncProcessRequest(sinkStack, msg, headers, stream);
            }
            else
            {
                _asyncMessage = null;
                AsyncProcessResponse(sinkStack, null, result.Headers, new MemoryStream(result.Response));
            }
        }
        /// <summary>
        /// Verarbeitet eine Anfragenachricht asynchron.
        /// </summary>
        /// <param name="sinkStack">Senkenstapel</param>
        /// <param name="msg">Remoting-Nachricht</param>
        /// <param name="headers">Anfrage-Header-Auflistung</param>
        /// <param name="stream">Anfrage-Datenstrom</param>
        public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders headers, Stream stream)
        {
            // Asynchroner Verarbeitungsstatus
            AsyncProcessingState state = null;

            lock (_lockObject)
            {
                // Asynchronen Verarbeitungsstatus erzeugen
                state = new AsyncProcessingState(msg, headers, ref stream, new Guid());

                //Methode aufrufen die Verarbeitung übernimmt
                DoProcessMessageBefore(msg, headers, stream);
            }
            // Aktuelle Senke auf den Senkenstapel legen (Damit ggf. die Verarbeitung der Antwort später asynchron aufgerufen werden kann)
            sinkStack.Push(this, state);

            // Nächste Kanalsenke aufrufen
            _next.AsyncProcessRequest(sinkStack, msg, headers, stream);
        }
Example #22
0
        public IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)
        {
            IMethodCallMessage methodCallMessage = msg as IMethodCallMessage;

            try
            {
                ITransportHeaders headers;
                Stream            stream;
                SerializeRequest(msg, out headers, out stream);
                ClientChannelSinkStack clientChannelSinkStack = new ClientChannelSinkStack(replySink);
                clientChannelSinkStack.Push(this, msg);
                nextSink.AsyncProcessRequest(clientChannelSinkStack, msg, headers, stream);
            }
            catch (Exception ex)
            {
                IMessage returnMessage = new ReturnMessage(ex, methodCallMessage);
                if (replySink == null)
                {
                    return(null);
                }
                replySink.SyncProcessMessage(returnMessage);
            }
            return(null);
        }
Example #23
0
        /// <summary>
        /// Requests asynchronous processing of a method call on the current sink.
        /// </summary>
        /// <param name="sinkStack">A stack of channel sinks that called this sink.</param>
        /// <param name="msg">The message to process.</param>
        /// <param name="headers">The headers to add to the outgoing message heading to the server.</param>
        /// <param name="stream">The stream headed to the transport sink.</param>
        public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders headers, Stream stream)
        {
            AsyncProcessingState state = null;
            Stream encryptedStream     = null;
            Guid   _secureTransactionID;

            lock (_lockObject)
            {
                // Start the secure transaction and save its identifier
                _secureTransactionID = StartSecureTransaction(msg, headers);

                // Prepare asynchronous state
                state = new AsyncProcessingState(msg, headers, ref stream, _secureTransactionID);

                // Encrypt the message
                encryptedStream = EncryptMessage(headers, stream);
            }

            // Push the current sink onto the sink stack so the processing of the response can be invoked asynchronously later
            sinkStack.Push(this, state);

            // Pass the message on to the next sink
            _next.AsyncProcessRequest(sinkStack, msg, headers, encryptedStream);
        }
 void IClientChannelSink.AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders headers, System.IO.Stream stream)
 {
     nextSink.AsyncProcessRequest(sinkStack, msg, headers, stream);
 }
 public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg,
                                 ITransportHeaders headers, Stream stream)
 {
     sinkStack.Push(this, null);
     nextClientSink.AsyncProcessRequest(sinkStack, msg, headers, stream);
 }