private IncomingTransportMessage TryDeserializeTransportMessage(ServiceBrokerMessage message)
 {
     using (var stream = new MemoryStream(message.Body))
     {
         try
         {
             var  payload = FastXmlTransportMessageSerializer.Deserialize(stream);
             var  enclosedMessageTypes = payload.Headers[StandardHeaders.EnclosedMessageTypes] as string ?? "";
             Type messageType          = null;
             foreach (var typeName in enclosedMessageTypes.Split(','))
             {
                 messageType = messageMapper.GetMappedTypeFor(typeName);
                 if (messageType != null)
                 {
                     break;
                 }
             }
             if (enclosedMessageTypes == null)
             {
                 var errorMessage = "Cannot decode type: " + enclosedMessageTypes;
                 logger.Error(errorMessage);
                 throw new CannotDeserializeMessageException(errorMessage);
             }
             var decodedMessage = messageEncoder.Decode(Encoding.UTF8.GetBytes(payload.Body), messageType);
             return(new IncomingTransportMessage(message.ConversationHandle.ToString(), payload.Headers, decodedMessage));
         }
         catch (Exception e)
         {
             logger.Error(e, "Cannot deserialize transport message for message {0} from queue {1}.", message.ConversationHandle, ServiceBrokerQueue);
             throw new CannotDeserializeMessageException(e);
         }
     }
 }
示例#2
0
        public async Task <string> ReadAsync(NetworkStream stream)
        {
            var buffer  = new byte[bufferSize];
            var builder = new StringBuilder();

            do
            {
                await stream.ReadAsync(buffer, 0, buffer.Length);

                var request = await _encoder.Decode(buffer);

                builder.Append(request);
            } while (stream.DataAvailable);

            return(builder.ToString());
        }
示例#3
0
        private object DecodeMessage(Message amqpMessage)
        {
            var  contentType          = amqpMessage.ApplicationProperties["LightRail.ContentType"] as string ?? "";
            var  enclosedMessageTypes = amqpMessage.ApplicationProperties["LightRail.EnclosedMessageTypes"] as string ?? "";
            Type messageType          = null;

            foreach (var typeName in enclosedMessageTypes.Split(','))
            {
                messageType = messageMapper.GetMappedTypeFor(typeName);
                if (messageType != null)
                {
                    break;
                }
            }
            var messageBodyBuffer = amqpMessage.Body as byte[];
            var message           = messageEncoder.Decode(messageBodyBuffer, messageType);

            return(message);
        }