Exemple #1
0
        public void AsyncProcessResponse(
            IClientResponseChannelSinkStack sinkStack_in,
            object state_in,
            ITransportHeaders headers_in,
            Stream stream_in
            )
        {
            #region decrypt...
            if (isHeaderEncrypted(headers_in))
            {
                stream_in
                    = EncryptionHelper.Decrypt(
                          stream_in,
                          false,
                          this.keyspath_,
                          this.clientid_
                          );
            }
            #endregion

            sinkStack_in.AsyncProcessResponse(
                headers_in,
                stream_in
                );
        }
Exemple #2
0
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream)
        {
            // process response como no lo he visto ejecutarse, mas vale prevenir.
            if (!stream.CanWrite)
            {
                try
                {
                    AbrirStream(ref stream);
                }
                catch
                {
                    AbrirStream(ref stream,
                                System.Convert.ToInt32((string)headers["TamañoComprimido"]));
                }
            }
            ProcessResponse(null, headers, ref stream, state);

            try
            {
                sinkStack.AsyncProcessResponse(headers, stream);
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
            }
        }
Exemple #3
0
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream)
        {
            RequestState rs = state as RequestState;

            if (rs != null && rs.didCompress)
            {
                bool compressOK = object.Equals(headers[CompressionHelper.CompressKey], CompressionHelper.CompressedFlag);
                if (!compressOK)
                {
                    serverCanCompress = false;
                    checkedCompress   = true;

                    // synchronously send the message now
                    rs.origStream.Position = rs.origPos;
                    ProcessMessage(rs.msg, rs.headers, rs.origStream, out headers, out stream);
                }
                else
                {
                    // decompress stuff
                    stream = CompressionHelper.DecompressStream(stream);

                    serverCanCompress = true;
                    checkedCompress   = true;
                }
                rs.origStream.Close();
            }

            // process through the rest of the stacks
            sinkStack.AsyncProcessResponse(headers, stream);
        }
Exemple #4
0
 public void AsyncProcessResponse(
     IClientResponseChannelSinkStack sinkStack,
     object state,
     ITransportHeaders headers,
     Stream stream)
 {
     // Send the request to the server.
     sinkStack.AsyncProcessResponse(headers, stream);
 }
Exemple #5
0
        /// <summary>
        /// Requests asynchronous processing of a response to a method call on the current sink.
        /// </summary>
        /// <param name="sinkStack">A stack of sinks that called this sink.</param>
        /// <param name="state">Information generated on the request side that is associated with this sink.</param>
        /// <param name="headers">The headers retrieved from the server response stream.</param>
        /// <param name="stream">The stream coming back from the transport sink.</param>
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream)
        {
            // Gets the asynchronous processing state
            AsyncProcessingState asyncState = (AsyncProcessingState)state;

            try
            {
                SecureTransactionStage currentStage = (SecureTransactionStage)Convert.ToInt32((string)headers[CommonHeaderNames.SECURE_TRANSACTION_STATE]);
                switch (currentStage)
                {
                case SecureTransactionStage.SendingEncryptedResult:                         // Get the encrypted response from the server

                    lock (_lockObject)
                    {
                        if (asyncState.SecureTransactionID.Equals(_secureTransactionID))
                        {
                            stream = DecryptResponse(stream, headers);
                        }
                        else
                        {
                            throw new CryptoRemotingException(LanguageResource.CryptoRemotingException_KeyChanged);
                        }
                    }
                    break;

                case SecureTransactionStage.UnknownTransactionID:                         // Bad transaction identifier

                    throw new CryptoRemotingException(LanguageResource.CryptoRemotingException_InvalidTransactionID);

                default:

                case SecureTransactionStage.Uninitialized:                         // Secure transaction is not yet set up
                    break;
                }
            }
            catch (CryptoRemotingException)
            {
                lock (_lockObject)
                {
                    // If remote transaction identifier matches the local secure transaction identifier, reset the shared key
                    if (_provider == null || asyncState.SecureTransactionID.Equals(_secureTransactionID))
                    {
                        ClearSharedKey();
                    }

                    ProcessMessage(asyncState.Message, asyncState.Headers, asyncState.Stream, out headers, out stream);
                }
            }
            finally
            {
                // Close the input stream
                asyncState.Stream.Close();
            }

            // Pass on to the next sink to continue processing
            sinkStack.AsyncProcessResponse(headers, stream);
        }
Exemple #6
0
        /// <summary>
        /// Requests asynchronous processing of a response to a method call on the current sink.
        /// </summary>
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state,
                                         ITransportHeaders headers, Stream stream)
        {
            // process response
            ProcessResponse(headers, ref stream);

            // forward to the next
            sinkStack.AsyncProcessResponse(headers, stream);
        }
 public void AsyncProcessResponse(
     IClientResponseChannelSinkStack stack,
     object state,
     ITransportHeaders headers,
     Stream stream
     )
 {
     stack.AsyncProcessResponse(headers, stream);
 }
Exemple #8
0
 public void AsyncProcessResponse(
     IClientResponseChannelSinkStack sinkStack,
     object state,
     ITransportHeaders responseHeaders,
     Stream responseStream)
 {
     Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss}    异步请求处理完毕:{state}");
     sinkStack.AsyncProcessResponse(responseHeaders, responseStream);
 }
        void IClientChannelSink.AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state,
            ITransportHeaders headers, Stream stream)
        {
            // process response
            ProcessResponse(null, headers, ref stream, state);

            // forward to the next
            sinkStack.AsyncProcessResponse(headers, stream);
        }
Exemple #10
0
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream)
        {
            AsyncProcessingState asyncState = (AsyncProcessingState)state;

            try
            {
                SecureTransaction transactType = (SecureTransaction)Convert.ToInt32((string)headers[CommonHeaders.Transaction]);
                switch (transactType)
                {
                case SecureTransaction.SendingEncryptedResult:
                {
                    lock (_transactionLock)
                    {
                        if (asyncState.ID.Equals(_transactID))
                        {
                            stream = DecryptResponse(stream, headers);
                        }
                        else
                        {
                            throw new SecureRemotingException("The key has changed since the message was decrypted.");
                        }
                    }
                    break;
                }

                case SecureTransaction.UnknownIdentifier:
                {
                    throw new SecureRemotingException("The server sink was unable to identify the client, most likely due to the connection information timing out.");
                }

                default:
                case SecureTransaction.Uninitialized:
                {
                    break;
                }
                }
            }
            catch (SecureRemotingException)
            {
                lock (_transactionLock)
                {
                    if (_provider == null || asyncState.ID.Equals(_transactID))
                    {
                        ClearSharedKey();
                    }
                    ProcessMessage(asyncState.Message, asyncState.Headers, asyncState.Stream, out headers, out stream);
                }
            }
            finally
            {
                asyncState.Stream.Close();
            }

            sinkStack.AsyncProcessResponse(headers, stream);
        }
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack,
                                         object state,
                                         ITransportHeaders headers,
                                         Stream stream)
        {
            // deflate the response
            stream =
                CompressionHelper.getUncompressedStreamCopy(stream);

            // forward the request
            sinkStack.AsyncProcessResponse(headers, stream);
        }
 public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack,
                                  object state, ITransportHeaders headers, Stream stream)
 {
     if (_asyncMessage != null)
     {
         try{
             object objCacheLimit = headers["X-Cache"];
             if (objCacheLimit != null && Convert.ToInt32(objCacheLimit) > 0)
             {
                 byte[] response = ExtractContents(stream);
                 cache.CacheResults(_asyncMessage, _asyncHeaders,
                                    new RemotingResult(response, headers, DateTime.UtcNow + TimeSpan.FromSeconds(Convert.ToInt32(objCacheLimit))), true);
                 sinkStack.AsyncProcessResponse(headers, new MemoryStream(response));
             }
         }
         catch (Exception) {
             sinkStack.AsyncProcessResponse(headers, stream);
         }
     }
     else
     {
         sinkStack.AsyncProcessResponse(headers, stream);
     }
 }
Exemple #13
0
        public void AsyncProcessResponse(
            IClientResponseChannelSinkStack sinkStack,
            object state,
            ITransportHeaders headers,
            Stream stream)
        {
            Exception ex = GetExceptionIfNecessary(ref headers, ref stream);

            if (ex != null)
            {
                sinkStack.DispatchException(ex);
            }
            else
            {
                sinkStack.AsyncProcessResponse(headers, stream);
            }
        }
Exemple #14
0
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack,
                                         object state,
                                         ITransportHeaders headers,
                                         Stream stream)
        {
            // decompress the stream if necessary
            String xcompress = (String)headers["X-Compress"];

            if (xcompress != null && xcompress == "yes")
            {
                stream = CompressionHelper.GetUncompressedStreamCopy(stream);
            }


            // forward the request
            sinkStack.AsyncProcessResponse(headers, stream);
        }
Exemple #15
0
        public void AsyncProcessResponse(
            IClientResponseChannelSinkStack stack,
            object state,
            ITransportHeaders headers,
            Stream stream
            )
        {
            #region Check response stream hash
            string hash = headers[HashHelper.C_HASH_ITEM] as string;
            //Debug.WriteLine("Client Side : response stream hash is " + hash);
            bool check = HashHelper.CheckHash(ref stream, hash);
            if (!check)
            {
                throw new Exception("Client Side : response stream header checksum error");
            }
            #endregion

            stack.AsyncProcessResponse(headers, stream);
        }
Exemple #16
0
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack,
                                         object state,
                                         ITransportHeaders headers,
                                         Stream stream)
        {
            if (headers["X-Encrypt"] != null && headers["X-Encrypt"].Equals("yes"))
            {
                byte[] IV =
                    Convert.FromBase64String((String)headers["X-EncryptIV"]);

                stream = EncryptionHelper.ProcessInboundStream(
                    stream,
                    _encryptionAlgorithm,
                    _encryptionKey,
                    IV);
            }

            // forward the request
            sinkStack.AsyncProcessResponse(headers, stream);
        }
Exemple #17
0
        public void AsyncProcessResponse(
            IClientResponseChannelSinkStack sinkStack_in,
            object state_in,
            ITransportHeaders headers_in,
            Stream stream_in
            )
        {
            #region uncompress...
            if (isHeaderCompressed_(headers_in))
            {
                stream_in
                    = CompressionHelper.GetUncompressedStreamCopy(
                          stream_in
                          );
            }
            #endregion

            sinkStack_in.AsyncProcessResponse(
                headers_in,
                stream_in
                );
        }
        /// <summary>
        /// Verarbeitet eine Antwort-Nachricht asynchron.
        /// </summary>
        /// <param name="sinkStack">Senkenstapel</param>
        /// <param name="state">Asynchroner Verarbeitungsstatus</param>
        /// <param name="headers">Anfrage-Header-Auflistung</param>
        /// <param name="stream">Anfrage-Datenstrom</param>
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream)
        {
            // Asychronen Verarbeitungsstatus abrufen
            AsyncProcessingState asyncState = (AsyncProcessingState)state;

            try
            {
                lock (_lockObject)
                {
                    //Todo: Was ist hier zu tun?
                }
            }
            finally
            {
            }

            ProcessMessage(asyncState.Message, asyncState.Headers, asyncState.Stream, out headers, out stream);

            asyncState.Stream.Close();

            // Verarbeitung in der nächsten Kanalsenke fortsetzen
            sinkStack.AsyncProcessResponse(headers, stream);
        }
 /// <summary>
 /// Processes an asynchronous response.
 /// </summary>
 /// <param name="sinkStack">Channel sink stack</param>
 /// <param name="state">State data</param>
 /// <param name="headers">Transport headers</param>
 /// <param name="stream">Response stream</param>
 public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream)
 {
     stream = OpenEnvelope(stream, headers);
     sinkStack.AsyncProcessResponse(headers, stream);
 }
 public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream)
 {
     stream = Zip.Decompress(stream);
     sinkStack.AsyncProcessResponse(headers, stream);
 }
Exemple #21
0
		public void AsyncProcessResponse(
			IClientResponseChannelSinkStack sinkStack_in,
			object state_in,
			ITransportHeaders headers_in,
			Stream stream_in
		) {
			#region decrypt...
			if (isHeaderEncrypted(headers_in)) {
				stream_in
					= EncryptionHelper.Decrypt(
						stream_in,
						false,
						this.keyspath_,
						this.clientid_
					);
			} 
			#endregion

			sinkStack_in.AsyncProcessResponse(
				headers_in,
				stream_in
			);
		} 
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream)
        {
            AsyncProcessingState asyncState = (AsyncProcessingState)state;

            try
            {
                SecureTransaction transactType = (SecureTransaction)Convert.ToInt32((string)headers[CommonHeaders.Transaction]);
                switch (transactType)
                {
                    case SecureTransaction.SendingEncryptedResult:
                        {
                            lock (_transactionLock)
                            {
                                if (asyncState.ID.Equals(_transactID))
                                {
                                    stream = DecryptResponse(stream, headers);
                                }
                                else
                                {
                                    throw new SecureRemotingException("The key has changed since the message was decrypted.");
                                }
                            }
                            break;
                        }
                    case SecureTransaction.UnknownIdentifier:
                        {
                            throw new SecureRemotingException("The server sink was unable to identify the client, most likely due to the connection information timing out.");
                        }
                    default:
                    case SecureTransaction.Uninitialized:
                        {
                            break;
                        }
                }
            }
            catch (SecureRemotingException)
            {
                lock (_transactionLock)
                {
                    if (_provider == null || asyncState.ID.Equals(_transactID))
                    {
                        ClearSharedKey();
                    }
                    ProcessMessage(asyncState.Message, asyncState.Headers, asyncState.Stream, out headers, out stream);
                }
            }
            finally
            {
                asyncState.Stream.Close();
            }

            sinkStack.AsyncProcessResponse(headers, stream);
        }
        /// <summary>Requests asynchronous processing of a response to a method call on the current sink.</summary>
        /// <param name="sinkStack">A stack of sinks that called this sink.</param>
        /// <param name="state">Information generated on the request side that is associated with this sink.</param>
        /// <param name="headers">The headers retrieved from the server response stream.</param>
        /// <param name="stream">The stream coming back from the transport sink.</param>
        public void AsyncProcessResponse(
			IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream)
        {
            // Get the async state we put on the stack
            AsyncProcessingState asyncState = (AsyncProcessingState)state;

            try
            {
                // Decrypt the response if possible
                SecureTransaction transactType = (SecureTransaction)Convert.ToInt32((string)headers[CommonHeaders.Transaction]);
                switch(transactType)
                {
                        // The only valid value; the server is sending results encrypted,
                        // so we need to decrypt them
                    case SecureTransaction.SendingEncryptedResult:
                        lock(_transactionLock)
                        {
                            if (asyncState.ID.Equals(_transactID)) stream = DecryptResponse(stream, headers);
                            else throw new SecureRemotingException("The key has changed since the message was decrypted.");
                        }
                        break;

                        // The server has no record of the client, so error out.
                        // If this were synchronous, we could try again, first renewing
                        // the connection information.  The best we can do here is null
                        // out our current connection information so that the next time
                        // through we'll create a new provider and identifier.
                    case SecureTransaction.UnknownIdentifier:
                        throw new SecureRemotingException(
                            "The server sink was unable to identify the client, " +
                            "most likely due to the connection information timing out.");

                        // Something happened and the response is not encrypted, i.e. there
                        // are no transport headers, or at least no transaction header, or it has
                        // been explicitly set by the server to Uninitialized.
                        // Regardless, do nothing.
                    default:
                    case SecureTransaction.Uninitialized:
                        break;
                }
            }
            catch(SecureRemotingException)
            {
                // We got back a secure remoting exceptionIt would be difficult to retry this as an
                // asynchronous call as we need to have the output ready to go before
                // we return.  Thus, we'll make a synchronous one by calling ProcessMessage()
                // just as if we were the previous sink.  Luckily, we kept all of the
                // necessary information sitting around.
                lock(_transactionLock) // This is a big, big lock, as are many locks in this app!  Oh well.
                {
                    if (_provider == null || asyncState.ID.Equals(_transactID)) ClearSharedKey();
                    ProcessMessage(
                        asyncState.Message, asyncState.Headers, asyncState.Stream,
                        out headers, out stream);
                }
            }
            finally
            {
                // Close the old stream just in case it hasn't been closed yet.
                asyncState.Stream.Close();
            }

            // Process through the rest of the sinks.
            sinkStack.AsyncProcessResponse(headers, stream);
        }
Exemple #24
0
 public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream)
 {
     CompressSinkHelper.DecompressStream(headers, stream);
     sinkStack.AsyncProcessResponse(headers, stream);
 }
Exemple #25
0
 public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream)
 {
     if (!stream.CanWrite)
     {
     try
     {
         OpenStream(ref stream);
     }
     catch
     {
         OpenStream(ref stream,
                     System.Convert.ToInt32( (string)headers["CompressedSize"]) );
     }
     }
     ProcessResponse(null, headers, ref stream, state);
     try
     {
     sinkStack.AsyncProcessResponse(headers, stream);
     }
     catch (Exception e)
     {
     Console.Write(e.Message);
     }
 }
        /// <summary>
        /// Verarbeitet eine Antwort-Nachricht asynchron.
        /// </summary>
        /// <param name="sinkStack">Senkenstapel</param>
        /// <param name="state">Asynchroner Verarbeitungsstatus</param>
        /// <param name="headers">Anfrage-Header-Auflistung</param>
        /// <param name="stream">Anfrage-Datenstrom</param>
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream)
        {
            // Asychronen Verarbeitungsstatus abrufen
            AsyncProcessingState asyncState = (AsyncProcessingState)state;

            try
            {

                lock (_lockObject)
                {
                    //Todo: Was ist hier zu tun?
                }

            }
            finally
            {
            }

            ProcessMessage(asyncState.Message, asyncState.Headers, asyncState.Stream, out headers, out stream);

            asyncState.Stream.Close();

            // Verarbeitung in der nächsten Kanalsenke fortsetzen
            sinkStack.AsyncProcessResponse(headers, stream);
        }
Exemple #27
0
        /// <summary>
        /// Verarbeitet eine Antwort-Nachricht asynchron.
        /// </summary>
        /// <param name="sinkStack">Senkenstapel</param>
        /// <param name="state">Asynchroner Verarbeitungsstatus</param>
        /// <param name="headers">Anfrage-Header-Auflistung</param>
        /// <param name="stream">Anfrage-Datenstrom</param>
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream)
        {
            // Asychronen Verarbeitungsstatus abrufen
            AsyncProcessingState asyncState = (AsyncProcessingState)state;

            try
            {
                // Aktuellen Verarbeitungsschritt der Sicherheitstransaktion ermitteln
                SecureTransactionStage currentStage = (SecureTransactionStage)Convert.ToInt32((string)headers[CommonHeaderNames.SECURE_TRANSACTION_STATE]);

                // Verarbeitungsschritt auswerten
                switch (currentStage)
                {
                case SecureTransactionStage.SendingEncryptedResult:     // Verschlüsselte Daten vom Server eingtroffen

                    lock (_lockObject)
                    {
                        // Wenn die Antwort auch tatsächlich zur aktuellen Sicherheitstransaktion gehört ...
                        if (asyncState.SecureTransactionID.Equals(_secureTransactionID))
                        {
                            // Datenstrom entschlüsseln
                            stream = DecryptResponse(stream, headers);
                        }
                        // Andernfalls ...
                        else
                        {
                            // Ausnahme werfen
                            throw new CryptoRemotingException(LanguageResource.CryptoRemotingException_KeyChanged);
                        }
                    }
                    break;

                case SecureTransactionStage.UnknownTransactionID:                         // Unbekannte Transaktionskennung

                    // Ausnahme werfen
                    throw new CryptoRemotingException(LanguageResource.CryptoRemotingException_InvalidTransactionID);

                default:

                case SecureTransactionStage.Uninitialized:     // Keine Sicherheitstransaktion eingerichtet
                    break;
                }
            }
            catch (CryptoRemotingException)
            {
                lock (_lockObject)
                {
                    // Wenn die gesendete Transaktionskennung mit der lokalen übereinstimmt ...
                    if (_provider == null || asyncState.SecureTransactionID.Equals(_secureTransactionID))
                    {
                        // Gemeinamen Schlüssel löschen
                        ClearSharedKey();
                    }

                    // Nachricht weiterverarbeiten
                    ProcessMessage(asyncState.Message, asyncState.Headers, asyncState.Stream, out headers, out stream);
                }
            }
            finally
            {
                // Datenstrom schließen
                asyncState.Stream.Close();
            }
            // Verarbeitung in der nächsten Kanalsenke fortsetzen
            sinkStack.AsyncProcessResponse(headers, stream);
        }
 public void AsyncProcessResponse(
     IClientResponseChannelSinkStack sinkStack,
     object state,
     ITransportHeaders headers,
     Stream stream)
 {
     // Send the request to the server.
     sinkStack.AsyncProcessResponse(headers, stream);
 }
        /// <summary>
        /// Requests asynchronous processing of a response to a method call on the current sink.
        /// </summary>
        /// <param name="sinkStack">A stack of sinks that called this sink.</param>
        /// <param name="state">Information generated on the request side that is associated with this sink.</param>
        /// <param name="headers">The headers retrieved from the server response stream.</param>
        /// <param name="stream">The stream coming back from the transport sink.</param>
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream)
        {
            // Gets the asynchronous processing state
            AsyncProcessingState asyncState = (AsyncProcessingState)state;

            try
            {
                SecureTransactionStage currentStage = (SecureTransactionStage)Convert.ToInt32((string)headers[CommonHeaderNames.SECURE_TRANSACTION_STATE]);
                switch (currentStage)
                {
                    case SecureTransactionStage.SendingEncryptedResult: // Get the encrypted response from the server

                        lock (_lockObject)
                        {
                            if (asyncState.SecureTransactionID.Equals(_secureTransactionID))
                                stream = DecryptResponse(stream, headers);
                            else
                                throw new CryptoRemotingException(LanguageResource.CryptoRemotingException_KeyChanged);
                        }
                        break;

                    case SecureTransactionStage.UnknownTransactionID: // Bad transaction identifier

                        throw new CryptoRemotingException(LanguageResource.CryptoRemotingException_InvalidTransactionID);

                    default:

                    case SecureTransactionStage.Uninitialized: // Secure transaction is not yet set up
                        break;
                }
            }
            catch (CryptoRemotingException)
            {
                lock (_lockObject)
                {
                    // If remote transaction identifier matches the local secure transaction identifier, reset the shared key
                    if (_provider == null || asyncState.SecureTransactionID.Equals(_secureTransactionID))
                        ClearSharedKey();

                    ProcessMessage(asyncState.Message, asyncState.Headers, asyncState.Stream, out headers, out stream);
                }
            }
            finally
            {
                // Close the input stream
                asyncState.Stream.Close();
            }

            // Pass on to the next sink to continue processing
            sinkStack.AsyncProcessResponse(headers, stream);
        }
		public void AsyncProcessResponse(
			IClientResponseChannelSinkStack sinkStack_in,
			object state_in,
			ITransportHeaders headers_in,
			Stream stream_in
		) {
			#region uncompress...
			if (isHeaderCompressed_(headers_in)) {
				stream_in
					= CompressionHelper.GetUncompressedStreamCopy(
						stream_in
					);
			} 
			#endregion

			sinkStack_in.AsyncProcessResponse(
				headers_in,
				stream_in
			);
		} 
 public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state,
                                  ITransportHeaders headers, Stream stream)
 {
     // перенаправляем вызов следующему приемнику в стеке
     sinkStack.AsyncProcessResponse(headers, stream);
 }
 public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, 
     ITransportHeaders headers, Stream stream)
 {
     // перенаправляем вызов следующему приемнику в стеке
     sinkStack.AsyncProcessResponse(headers, stream);
 }
Exemple #33
0
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream)
        {
            // process response como no lo he visto ejecutarse, mas vale prevenir.
            if (!stream.CanWrite)
            {
                try
                {
                    AbrirStream(ref stream);
                }
                catch
                {
                    AbrirStream(ref stream,
                        System.Convert.ToInt32( (string)headers["TamañoComprimido"]) );
                }
            }
            ProcessResponse(null, headers, ref stream, state);

            try
            {
                sinkStack.AsyncProcessResponse(headers, stream);
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
            }
        }
Exemple #34
0
        /// <summary>Requests asynchronous processing of a response to a method call on the current sink.</summary>
        /// <param name="sinkStack">A stack of sinks that called this sink.</param>
        /// <param name="state">Information generated on the request side that is associated with this sink.</param>
        /// <param name="headers">The headers retrieved from the server response stream.</param>
        /// <param name="stream">The stream coming back from the transport sink.</param>
        public void AsyncProcessResponse(
            IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream)
        {
            // Get the async state we put on the stack
            AsyncProcessingState asyncState = (AsyncProcessingState)state;

            try
            {
                // Decrypt the response if possible
                SecureTransaction transactType = (SecureTransaction)Convert.ToInt32((string)headers[CommonHeaders.Transaction]);
                switch (transactType)
                {
                // The only valid value; the server is sending results encrypted,
                // so we need to decrypt them
                case SecureTransaction.SendingEncryptedResult:
                    lock (_transactionLock)
                    {
                        if (asyncState.ID.Equals(_transactID))
                        {
                            stream = DecryptResponse(stream, headers);
                        }
                        else
                        {
                            throw new SecureRemotingException("The key has changed since the message was decrypted.");
                        }
                    }
                    break;

                // The server has no record of the client, so error out.
                // If this were synchronous, we could try again, first renewing
                // the connection information.  The best we can do here is null
                // out our current connection information so that the next time
                // through we'll create a new provider and identifier.
                case SecureTransaction.UnknownIdentifier:
                    throw new SecureRemotingException(
                              "The server sink was unable to identify the client, " +
                              "most likely due to the connection information timing out.");

                // Something happened and the response is not encrypted, i.e. there
                // are no transport headers, or at least no transaction header, or it has
                // been explicitly set by the server to Uninitialized.
                // Regardless, do nothing.
                default:
                case SecureTransaction.Uninitialized:
                    break;
                }
            }
            catch (SecureRemotingException)
            {
                // We got back a secure remoting exceptionIt would be difficult to retry this as an
                // asynchronous call as we need to have the output ready to go before
                // we return.  Thus, we'll make a synchronous one by calling ProcessMessage()
                // just as if we were the previous sink.  Luckily, we kept all of the
                // necessary information sitting around.
                lock (_transactionLock)                // This is a big, big lock, as are many locks in this app!  Oh well.
                {
                    if (_provider == null || asyncState.ID.Equals(_transactID))
                    {
                        ClearSharedKey();
                    }
                    ProcessMessage(
                        asyncState.Message, asyncState.Headers, asyncState.Stream,
                        out headers, out stream);
                }
            }
            finally
            {
                // Close the old stream just in case it hasn't been closed yet.
                asyncState.Stream.Close();
            }

            // Process through the rest of the sinks.
            sinkStack.AsyncProcessResponse(headers, stream);
        }
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream)
        {
            RequestState rs = state as RequestState;
            if (rs != null && rs.didCompress) {
                bool compressOK = object.Equals(headers[CompressionHelper.CompressKey], CompressionHelper.CompressedFlag);
                if (!compressOK) {
                    serverCanCompress = false;
                    checkedCompress = true;

                    // synchronously send the message now
                    rs.origStream.Position = rs.origPos;
                    ProcessMessage(rs.msg, rs.headers, rs.origStream, out headers, out stream);
                }
                else {
                    // decompress stuff
                    stream = CompressionHelper.DecompressStream(stream);

                    serverCanCompress = true;
                    checkedCompress = true;
                }
                rs.origStream.Close();
            }

            // process through the rest of the stacks
            sinkStack.AsyncProcessResponse(headers, stream);
        }
        /// <summary>
        /// Verarbeitet eine Antwort-Nachricht asynchron.
        /// </summary>
        /// <param name="sinkStack">Senkenstapel</param>
        /// <param name="state">Asynchroner Verarbeitungsstatus</param>
        /// <param name="headers">Anfrage-Header-Auflistung</param>
        /// <param name="stream">Anfrage-Datenstrom</param>
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream)
        {
            // Asychronen Verarbeitungsstatus abrufen
            AsyncProcessingState asyncState = (AsyncProcessingState)state;

            try
            {
                // Aktuellen Verarbeitungsschritt der Sicherheitstransaktion ermitteln
                SecureTransactionStage currentStage = (SecureTransactionStage)Convert.ToInt32((string)headers[CommonHeaderNames.SECURE_TRANSACTION_STATE]);

                // Verarbeitungsschritt auswerten
                switch (currentStage)
                {
                    case SecureTransactionStage.SendingEncryptedResult: // Verschlüsselte Daten vom Server eingtroffen

                        lock (_lockObject)
                        {
                            // Wenn die Antwort auch tatsächlich zur aktuellen Sicherheitstransaktion gehört ...
                            if (asyncState.SecureTransactionID.Equals(_secureTransactionID))
                                // Datenstrom entschlüsseln
                                stream = DecryptResponse(stream, headers);
                            // Andernfalls ...
                            else
                                // Ausnahme werfen
                                throw new CryptoRemotingException(LanguageResource.CryptoRemotingException_KeyChanged);
                        }
                        break;

                    case SecureTransactionStage.UnknownTransactionID: // Unbekannte Transaktionskennung

                        // Ausnahme werfen
                        throw new CryptoRemotingException(LanguageResource.CryptoRemotingException_InvalidTransactionID);

                    default:

                    case SecureTransactionStage.Uninitialized: // Keine Sicherheitstransaktion eingerichtet
                        break;
                }
            }
            catch (CryptoRemotingException)
            {
                lock (_lockObject)
                {
                    // Wenn die gesendete Transaktionskennung mit der lokalen übereinstimmt ...
                    if (_provider == null || asyncState.SecureTransactionID.Equals(_secureTransactionID))
                        // Gemeinamen Schlüssel löschen
                        ClearSharedKey();

                    // Nachricht weiterverarbeiten
                    ProcessMessage(asyncState.Message, asyncState.Headers, asyncState.Stream, out headers, out stream);
                }
            }
            finally
            {
                // Datenstrom schließen
                asyncState.Stream.Close();
            }
            // Verarbeitung in der nächsten Kanalsenke fortsetzen
            sinkStack.AsyncProcessResponse(headers, stream);
        }