本文整理汇总了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));
}
//.........这里部分代码省略.........
示例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));
}
}
示例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;
}
示例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;
}