本文整理汇总了C#中Message.WriteBodyContents方法的典型用法代码示例。如果您正苦于以下问题:C# Message.WriteBodyContents方法的具体用法?C# Message.WriteBodyContents怎么用?C# Message.WriteBodyContents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message
的用法示例。
在下文中一共展示了Message.WriteBodyContents方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvokeAsync
public async Task<Message> InvokeAsync(Message msg)
{
var context = WebOperationContext.Current;
object value;
Stream s = null;
if (msg.Properties.TryGetValue("WebBodyFormatMessageProperty", out value))
{
var prop = value as WebBodyFormatMessageProperty;
if (prop != null && (prop.Format == WebContentFormat.Json || prop.Format == WebContentFormat.Raw))
{
s = StreamMessageHelper.GetStream(msg);
}
}
else
{
var ms = new MemoryStream();
using (var xw = XmlDictionaryWriter.CreateTextWriter(ms, Encoding.UTF8, false))
{
msg.WriteBodyContents(xw);
}
ms.Seek(0, SeekOrigin.Begin);
s = ms;
}
var request = MakeHttpRequestMessageFrom(context.IncomingRequest, s, _config.BufferRequestContent);
var response = await _serverInvoker.SendAsync(request, CancellationToken.None);
CopyHttpResponseMessageToOutgoingResponse(response, context.OutgoingResponse);
var stream = response.Content != null ? await response.Content.ReadAsStreamAsync() : null;
return StreamMessageHelper.CreateMessage(MessageVersion.None, "GETRESPONSE", stream ?? new MemoryStream());
}
示例2: FormattedMessage
private void FormattedMessage(Message message, char format, StringBuilder output)
{
using (var writer = CreateWriter(message, format, output))
{
switch (format)
{
case 'b':
message.WriteBody(writer);
break;
case 'B':
message.WriteBodyContents(writer);
break;
case 's':
message.WriteStartBody(writer);
break;
case 'S':
message.WriteStartEnvelope(writer);
break;
case 'm':
case 'M':
message.WriteMessage(writer);
break;
default:
return;
}
writer.Flush();
}
}
示例3: CompressMessage
public Message CompressMessage(Message sourceMessage)
{
byte[] buffer;
//using (XmlDictionaryReader reader1 = sourceMessage.GetReaderAtBodyContents())
//{
// buffer = Encoding.UTF8.GetBytes(reader1.ReadOuterXml());
//}
MemoryStream ms = new MemoryStream();
XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(ms, Encoding.UTF8);
sourceMessage.WriteBodyContents(writer);
writer.Flush();
buffer = ms.ToArray();
if (buffer.Length == 0)
{
Message emptyMessage = Message.CreateMessage(sourceMessage.Version, (string)null);
sourceMessage.Headers.CopyHeadersFrom(sourceMessage);
sourceMessage.Properties.CopyProperties(sourceMessage.Properties);
emptyMessage.Close();
return emptyMessage;
}
byte[] compressedData = DataCompressor.Compress(buffer, this.Algorithm);
string copressedBody = CompressionUtil.CreateCompressedBody(compressedData);
XmlTextReader reader = new XmlTextReader(new StringReader(copressedBody), new NameTable());
Message message2 = Message.CreateMessage(sourceMessage.Version, null, (XmlReader)reader);
message2.Headers.CopyHeadersFrom(sourceMessage);
message2.Properties.CopyProperties(sourceMessage.Properties);
message2.AddCompressionHeader(this.Algorithm);
sourceMessage.Close();
return message2;
}
示例4: Base64BodyMessage
private Message Base64BodyMessage(Message ora_msg)
{
MemoryStream ms = new MemoryStream();
XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(ms, Encoding.UTF8);
ora_msg.WriteBodyContents(writer);
writer.Flush();
string body = System.Text.Encoding.UTF8.GetString(ms.GetBuffer());
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(body);
body = Convert.ToBase64String(buffer);
Message msg = Message.CreateMessage(ora_msg.Version, ora_msg.Headers.Action, new MyBodyWriter(body));
ora_msg.Close();
return msg;
}
示例5: BeginInvoke
public IAsyncResult BeginInvoke(Message msg, AsyncCallback callback, object state)
{
var context = WebOperationContext.Current;
object value;
Stream s = null;
if (msg.Properties.TryGetValue("WebBodyFormatMessageProperty", out value))
{
var prop = value as WebBodyFormatMessageProperty;
if (prop != null && (prop.Format == WebContentFormat.Json || prop.Format == WebContentFormat.Raw))
{
s = StreamMessageHelper.GetStream(msg);
}
}else{
var ms = new MemoryStream();
using(var xw = XmlDictionaryWriter.CreateTextWriter(ms, Encoding.UTF8, false))
{
msg.WriteBodyContents(xw);
}
ms.Seek(0, SeekOrigin.Begin);
s = ms;
}
return DispatchToHttpServer(context.IncomingRequest, s, context.OutgoingResponse, _config.BufferRequestContent, callback, state);
}
示例6: InvokeAsync
public async Task<Message> InvokeAsync(Message msg)
{
var webOperContext = WebOperationContext.Current;
object value;
Stream s = null;
if (msg.Properties.TryGetValue("WebBodyFormatMessageProperty", out value))
{
var prop = value as WebBodyFormatMessageProperty;
if (prop != null && (prop.Format == WebContentFormat.Json || prop.Format == WebContentFormat.Raw))
{
s = StreamMessageHelper.GetStream(msg);
}
}
else
{
var ms = new MemoryStream();
using (var xw = XmlDictionaryWriter.CreateTextWriter(ms, Encoding.UTF8, false))
{
msg.WriteBodyContents(xw);
}
ms.Seek(0, SeekOrigin.Begin);
s = ms;
}
var outputStream = new MemoryStream();
var onSendingHeadersHandlers = new List<Tuple<Action<object>, object>> ();
var owinContext = MakeOwinContextFrom(webOperContext.IncomingRequest, s, outputStream, onSendingHeadersHandlers);
await _next.Invoke(owinContext.Environment);
onSendingHeadersHandlers.Reverse();
foreach (var t in onSendingHeadersHandlers)
{
t.Item1(t.Item2);
}
CopyOwinContextToOutgoingResponse(owinContext, webOperContext.OutgoingResponse);
var buffer = outputStream.GetBuffer();
return StreamMessageHelper.CreateMessage(MessageVersion.None, "GETRESPONSE", new MemoryStream(buffer));
}
示例7: GetString
private string GetString(Message message)
{
using (MemoryStream stream = new MemoryStream())
using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateBinaryWriter(stream))
{
message.WriteBodyContents(writer);
writer.Flush();
stream.Position = 0;
return this.GetString(stream);
}
}
示例8: GetBodyInnerContentStream
/// <summary>
/// Gets stream of inner element content of the message body.
/// </summary>
private Stream GetBodyInnerContentStream(Message message)
{
using (var bodyStream = new MemoryStream())
{
using (XmlDictionaryWriter bodyWriter = XmlDictionaryWriter.CreateBinaryWriter(bodyStream))
{
message.WriteBodyContents(bodyWriter);
bodyWriter.Flush();
bodyStream.Position = 0;
using (var bodyReader = XmlDictionaryReader.CreateBinaryReader(bodyStream, XmlDictionaryReaderQuotas.Max))
{
bodyReader.MoveToStartElement();
var contentStream = new MemoryStream(bodyReader.ReadElementContentAsBase64());
contentStream.Position = 0;
return contentStream;
}
}
}
}
示例9: WriteMessage
/// <summary>
/// Writes a message to a specified stream.
/// </summary>
/// <remarks>An actual serialization is performed rigth here.</remarks>
/// <param name="message">The Message to write to the stream.</param>
/// <param name="stream">The Stream object to which the message is written.</param>
public override void WriteMessage(Message message, Stream stream)
{
try
{
using(var ms = new MemoryStream())
{
//Read AMFX message
var writer = XmlDictionaryWriter.CreateDictionaryWriter(AmfxWriter.Create(ms));
message.WriteBodyContents(writer);
writer.Flush();
ms.Seek(0, SeekOrigin.Begin);
//Encode binary AMF packet from AMFX data
_serializer.WriteObject(stream, AmfxReader.Create(ms));
}
}
finally
{
message.Close();
}
}
示例10: GetMessageBodyAsElement
static XDocument GetMessageBodyAsElement(Message m)
{
var enc = new UTF8Encoding(false);
using (var buf = new MemoryStream())
{
using (var w = XmlDictionaryWriter.CreateTextWriter(buf, enc, false))
{
m.WriteBodyContents(w);
}
buf.Position = 0;
using (var r = new StreamReader(buf, enc))
{
return XDocument.Load(r);
}
}
}
示例11: GetBodyContents
private byte[] GetBodyContents(Message message)
{
using (MemoryStream ms = new MemoryStream())
{
XmlDictionaryWriter bodyWriter =
XmlDictionaryWriter.CreateBinaryWriter(ms);
message.WriteBodyContents(bodyWriter);
bodyWriter.Flush();
ms.Position = 0;
return ms.ToArray();
}
}
示例12: CreateReaderFromMessage
private static XmlDictionaryReader CreateReaderFromMessage(Message message)
{
MemoryStream ms = new MemoryStream();
byte[] buffer;
using (message)
{
using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateBinaryWriter(ms))
{
message.WriteBodyContents(writer);
writer.Flush();
buffer = ms.ToArray();
foreach (byte b in buffer)
{
Console.Write((char)b);
}
}
}
XmlDictionaryReader xmlDictionaryReader = XmlDictionaryReader.CreateBinaryReader(buffer, XmlDictionaryReaderQuotas.Max);
return xmlDictionaryReader;
}