Пример #1
0
        public ChannelMessage ToChannelMessage(RpcException exception)
        {
            using (var memStream = new MemoryStream())
            {
                var formatter = new BinaryFormatter();
                formatter.Serialize(memStream, exception.Exception);
                var binding = new RpcExceptionBinding
                {
                    QueryId   = exception.QueryId,
                    Exception = Convert.ToBase64String(memStream.ToArray())
                };

                var payload = Encoding.UTF8.GetBytes(
                    m_JsonSerializer.Serialize(binding));

                return(new ChannelMessage((int)ChannelMessageType.RpcException, payload));
            }
        }
Пример #2
0
        private static RpcException FromBinding(RpcExceptionBinding binding)
        {
            var formatter = new BinaryFormatter();

            try
            {
                using (var memStream = new MemoryStream(Convert.FromBase64String(binding.Exception)))
                {
                    return(new RpcException(
                               binding.QueryId,
                               (Exception)formatter.Deserialize(memStream)));
                }
            }
            catch (Exception)
            {
                return(new RpcException(binding.QueryId, new Exception("The operation could not be completed.")));
                // TODO: Log this as error
            }
        }