当前位置: 首页>>代码示例>>C#>>正文


C# MessageEncoder.ReadMessage方法代码示例

本文整理汇总了C#中MessageEncoder.ReadMessage方法的典型用法代码示例。如果您正苦于以下问题:C# MessageEncoder.ReadMessage方法的具体用法?C# MessageEncoder.ReadMessage怎么用?C# MessageEncoder.ReadMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MessageEncoder的用法示例。


在下文中一共展示了MessageEncoder.ReadMessage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetMessageAndProperties

        /// <summary>
        /// Gets the message body and properties.
        /// </summary>
        /// <param name="builder">The string builder object used to accumulate the trace message.</param>
        /// <param name="inboundMessage">The inbound message.</param>
        /// <param name="encoder">The message encoder used to decode a WCF message.</param>
        public void GetMessageAndProperties(StringBuilder builder, BrokeredMessage inboundMessage, MessageEncoder encoder)
        {
            string messageText = null;
            Stream stream = null;

            if (inboundMessage == null)
            {
                return;
            }
            try
            {
                var messageClone = inboundMessage.Clone();
                stream = messageClone.GetBody<Stream>();
                if (stream != null)
                {
                    var stringBuilder = new StringBuilder();
                    var message = encoder.ReadMessage(stream, MaxBufferSize);
                    using (var reader = message.GetReaderAtBodyContents())
                    {
                        // The XmlWriter is used just to indent the XML message
                        var settings = new XmlWriterSettings { Indent = true };
                        using (var writer = XmlWriter.Create(stringBuilder, settings))
                        {
                            writer.WriteNode(reader, true);
                        }
                    }
                    messageText = stringBuilder.ToString();
                }
            }
            catch (Exception)
            {
                try
                {
                    var messageClone = inboundMessage.Clone();
                    stream = messageClone.GetBody<Stream>();
                    if (stream != null)
                    {
                        var message = encoder.ReadMessage(stream, MaxBufferSize);
                        using (var reader = message.GetReaderAtBodyContents())
                        {
                            messageText = reader.ReadString();
                        }
                    }
                }
                catch (Exception)
                {
                    try
                    {
                        if (stream != null)
                        {
                            try
                            {
                                stream.Seek(0, SeekOrigin.Begin);
                                var serializer = new CustomDataContractBinarySerializer(typeof(string));
                                messageText = serializer.ReadObject(stream) as string;
                            }
                            catch (Exception)
                            {
                                try
                                {
                                    stream.Seek(0, SeekOrigin.Begin);
                                    using (var reader = new StreamReader(stream))
                                    {
                                        messageText = reader.ReadToEnd();
                                    }
                                }
                                catch (Exception)
                                {
                                    messageText = UnableToReadMessageBody;
                                }
                            }
                        }
                        else
                        {
                            messageText = UnableToReadMessageBody;
                        }
                    }
                    catch (Exception)
                    {
                        messageText = UnableToReadMessageBody;
                    }
                }
            }
            builder.AppendLine(ReceivedMessagePayloadHeader);
            builder.AppendLine(string.Format(MessageTextFormat, messageText));
            if (inboundMessage.Properties.Any())
            {
                builder.AppendLine(ReceivedMessagePropertiesHeader);
                foreach (var p in inboundMessage.Properties)
                {
                    builder.AppendLine(string.Format(MessagePropertyFormat,
                                                     p.Key,
                                                     p.Value));
                }
//.........这里部分代码省略.........
开发者ID:abombss,项目名称:ServiceBusExplorer,代码行数:101,代码来源:ServiceBusHelper.cs

示例2: DecodeSessiongramMessage

        static Message DecodeSessiongramMessage(
            MsmqInputSessionChannelListener listener,
            MsmqInputSessionChannel channel,
            MessageEncoder encoder,
            MsmqMessageProperty messageProperty,
            byte[] buffer,
            int offset,
            int size)
        {
            if (size > listener.MaxReceivedMessageSize)
            {
                channel.FaultChannel();
                listener.MsmqReceiveHelper.FinalDisposition(messageProperty);
                throw listener.NormalizePoisonException(messageProperty.LookupId, MaxMessageSizeStream.CreateMaxReceivedMessageSizeExceededException(listener.MaxReceivedMessageSize));
            }

            // Fix for CSDMain bug 17842
            // size is derived from user data, check for corruption
            if ((size + offset) > buffer.Length)
            {
                listener.MsmqReceiveHelper.FinalDisposition(messageProperty);
                throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(SR.GetString(SR.MsmqBadFrame)));
            }

            byte[] envelopeBuffer = listener.BufferManager.TakeBuffer(size);
            Buffer.BlockCopy(buffer, offset, envelopeBuffer, 0, size);
            try
            {
                Message message = null;
                using (MsmqDiagnostics.BoundDecodeOperation())
                {
                    message = encoder.ReadMessage(new ArraySegment<byte>(envelopeBuffer, 0, size), listener.BufferManager);
                    MsmqDiagnostics.TransferFromTransport(message);
                }
                return message;
            }
            catch (XmlException e)
            {
                channel.FaultChannel();
                listener.MsmqReceiveHelper.FinalDisposition(messageProperty);
                throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(SR.GetString(SR.MsmqBadXml), e));
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:43,代码来源:MsmqDecodeHelper.cs

示例3: DecodeSessiongramMessage

 private static Message DecodeSessiongramMessage(MsmqInputSessionChannelListener listener, MsmqInputSessionChannel channel, MessageEncoder encoder, MsmqMessageProperty messageProperty, byte[] buffer, int offset, int size)
 {
     Message message2;
     if (size > listener.MaxReceivedMessageSize)
     {
         channel.FaultChannel();
         listener.MsmqReceiveHelper.FinalDisposition(messageProperty);
         throw listener.NormalizePoisonException(messageProperty.LookupId, MaxMessageSizeStream.CreateMaxReceivedMessageSizeExceededException(listener.MaxReceivedMessageSize));
     }
     if ((size + offset) > buffer.Length)
     {
         listener.MsmqReceiveHelper.FinalDisposition(messageProperty);
         throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(System.ServiceModel.SR.GetString("MsmqBadFrame")));
     }
     byte[] dst = listener.BufferManager.TakeBuffer(size);
     Buffer.BlockCopy(buffer, offset, dst, 0, size);
     try
     {
         Message message = null;
         using (MsmqDiagnostics.BoundDecodeOperation())
         {
             message = encoder.ReadMessage(new ArraySegment<byte>(dst, 0, size), listener.BufferManager);
             MsmqDiagnostics.TransferFromTransport(message);
         }
         message2 = message;
     }
     catch (XmlException exception)
     {
         channel.FaultChannel();
         listener.MsmqReceiveHelper.FinalDisposition(messageProperty);
         throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(System.ServiceModel.SR.GetString("MsmqBadXml"), exception));
     }
     return message2;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:34,代码来源:MsmqDecodeHelper.cs

示例4: DecodeMessage

        public static Message DecodeMessage(DuplicateMessageDetector duplicateDetector, MessageEncoder encoder, BufferManager bufferManager, ArraySegment<byte> data, IPEndPoint remoteEndPoint, int interfaceIndex, bool ignoreSerializationException, out string messageHash)
        {
            Fx.Assert(data != null, "data can't be null");
            Fx.Assert(remoteEndPoint != null, "remoteEndPoint can't be null");
            Fx.Assert(encoder != null, "encoder can't be null");
            Fx.Assert(bufferManager != null, "bufferManager can't be null");
            
            Message message = null;

            messageHash = null;

            if (duplicateDetector == null  || !duplicateDetector.IsDuplicate(data, out messageHash))
            {
                try
                {
                    message = encoder.ReadMessage(data, bufferManager);
                }
                catch (XmlException error)
                {
                    // Don't throw serialization exceptions when the channel supports Multicast
                    if (!ignoreSerializationException)
                    {
                        throw;
                    }

                    FxTrace.Exception.AsWarning(error);
                }

                if (message != null)
                {
                    message.Properties.Add(RemoteEndpointMessageProperty.Name,
                        new RemoteEndpointMessageProperty(remoteEndPoint.Address.ToString(), remoteEndPoint.Port));

                    NetworkInterfaceMessageProperty networkInterfaceMessageProperty = new NetworkInterfaceMessageProperty(interfaceIndex);
                    networkInterfaceMessageProperty.AddTo(message);
                }
            }

            return message;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:40,代码来源:UdpUtility.cs


注:本文中的MessageEncoder.ReadMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。