本文整理汇总了C#中Message.WriteMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Message.WriteMessage方法的具体用法?C# Message.WriteMessage怎么用?C# Message.WriteMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message
的用法示例。
在下文中一共展示了Message.WriteMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
示例2: MessageToString
private string MessageToString(ref Message message)
{
WebContentFormat messageFormat = this.GetMessageContentFormat(message);
MemoryStream ms = new MemoryStream();
XmlDictionaryWriter writer = null;
switch (messageFormat)
{
case WebContentFormat.Default:
case WebContentFormat.Xml:
writer = XmlDictionaryWriter.CreateTextWriter(ms);
break;
case WebContentFormat.Json:
writer = JsonReaderWriterFactory.CreateJsonWriter(ms);
break;
case WebContentFormat.Raw:
// special case for raw, easier implemented separately
return this.ReadRawBody(ref message);
}
message.WriteMessage(writer);
writer.Flush();
string messageBody = Encoding.UTF8.GetString(ms.ToArray());
ms.Position = 0;
XmlDictionaryReader reader = JsonReaderWriterFactory.CreateJsonReader(ms, XmlDictionaryReaderQuotas.Max);
Message newMessage = Message.CreateMessage(reader, int.MaxValue, message.Version);
newMessage.Properties.CopyProperties(message.Properties);
message = newMessage;
return messageBody;
}
示例3: Echo
public Message Echo (Message msg)
{
using (XmlWriter w = XmlWriter.Create (Console.Out)) {
msg.WriteMessage (w);
}
throw new NotImplementedException ("you are here.");
}
示例4: WriteMessage
public override void WriteMessage(Message message, Stream stream)
{
using (XmlWriter writer = XmlWriter.Create(stream, _writerSettings))
{
message.WriteMessage(writer);
}
}
示例5: WriteMessage
static void WriteMessage(Message message, string fileName)
{
using (XmlWriter writer = new XmlTextWriter(fileName, Encoding.UTF8))
{
message.WriteMessage(writer);
}
Process.Start(fileName);
}
示例6: LogMessage
private void LogMessage(Message message)
{
StringBuilder sb = new StringBuilder();
using (System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(sb))
{
message.WriteMessage(xw);
xw.Close();
}
Logger.Instance.Log.Trace("Message :\n{0}", sb.ToString());
}
示例7: Deserialize
public static object Deserialize(Message message, Type messageType)
{
using (var memoryStream = new MemoryStream())
{
XmlDictionaryWriter writer = JsonReaderWriterFactory.CreateJsonWriter(memoryStream);
message.WriteMessage(writer);
writer.Flush();
var serializer = new DataContractJsonSerializer(messageType);
memoryStream.Seek(0, SeekOrigin.Begin);
return serializer.ReadObject(memoryStream);
}
}
示例8: DeserializeRequest
public void DeserializeRequest(Message message, object[] parameters)
{
using (var mss = new MemoryStream())
{
using (var messageWriter = JsonReaderWriterFactory.CreateJsonWriter(mss))
{
message.WriteMessage(messageWriter);
messageWriter.Flush();
parameters[0] = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(mss.ToArray()), _operation.Messages[0].Body.Parts[0].Type);
}
}
}
示例9: MessageEnvelope
private static XDocument MessageEnvelope(Message message)
{
using (var stream = new MemoryStream())
{
using (var writer = XmlDictionaryWriter.CreateTextWriter(stream))
{
message.WriteMessage(writer);
}
stream.Seek(0, SeekOrigin.Begin);
var doc = XDocument.Load(stream);
return doc;
}
}
示例10: WriteMessage
public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
{
var stream = new MemoryStream();
var writer = XmlWriter.Create(stream, _writerSettings);
message.WriteMessage(writer);
writer.Close();
var messageBytes = stream.GetBuffer();
var messageLength = (int)stream.Position;
stream.Close();
var totalLength = messageLength + messageOffset;
var totalBytes = bufferManager.TakeBuffer(totalLength);
Array.Copy(messageBytes, 0, totalBytes, messageOffset, messageLength);
var byteArray = new ArraySegment<byte>(totalBytes, messageOffset, messageLength);
return byteArray;
}
示例11: WriteMessage
public ArraySegment<byte> WriteMessage(Message message, BufferManager bufferManager, int initialOffset, int maxSizeQuota)
{
int num;
ArraySegment<byte> segment;
if (maxSizeQuota <= (0x7fffffff - initialOffset))
{
num = maxSizeQuota + initialOffset;
}
else
{
num = 0x7fffffff;
}
int initialSize = this.PredictMessageSize();
if (initialSize > num)
{
initialSize = num;
}
else if (initialSize < initialOffset)
{
initialSize = initialOffset;
}
try
{
int num3;
this.stream.Init(initialSize, maxSizeQuota, num, bufferManager);
this.stream.Skip(initialOffset);
XmlDictionaryWriter writer = this.TakeXmlWriter(this.stream);
this.OnWriteStartMessage(writer);
message.WriteMessage(writer);
this.OnWriteEndMessage(writer);
writer.Flush();
this.ReturnXmlWriter(writer);
byte[] array = this.stream.ToArray(out num3);
this.RecordActualMessageSize(num3);
segment = new ArraySegment<byte>(array, initialOffset, num3 - initialOffset);
}
finally
{
this.stream.Clear();
}
return segment;
}
示例12: WriteMessage
public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
{
MemoryStream stream = new MemoryStream();
XmlWriter writer = XmlWriter.Create(stream, new XmlWriterSettings());
writer.WriteStartElement("CustomEnvelope", "");
message.WriteMessage(writer);
writer.WriteEndElement();
writer.Close();
byte[] messageBytes = stream.GetBuffer();
int messageLength = (int)stream.Position;
stream.Close();
int totalLength = messageLength + messageOffset;
byte[] totalBytes = bufferManager.TakeBuffer(totalLength);
Array.Copy(messageBytes, 0, totalBytes, messageOffset, messageLength);
ArraySegment<byte> byteArray = new ArraySegment<byte>(totalBytes, messageOffset, messageLength);
return byteArray;
}
示例13: WriteMessage
public ArraySegment<byte> WriteMessage(Message message, BufferManager bufferManager, int initialOffset, int maxSizeQuota)
{
int effectiveMaxSize;
// make sure that maxSize has room for initialOffset without overflowing, since
// the effective buffer size is message size + initialOffset
if (maxSizeQuota <= int.MaxValue - initialOffset)
effectiveMaxSize = maxSizeQuota + initialOffset;
else
effectiveMaxSize = int.MaxValue;
int predictedMessageSize = PredictMessageSize();
if (predictedMessageSize > effectiveMaxSize)
predictedMessageSize = effectiveMaxSize;
else if (predictedMessageSize < initialOffset)
predictedMessageSize = initialOffset;
try
{
_stream.Init(predictedMessageSize, maxSizeQuota, effectiveMaxSize, bufferManager);
_stream.Skip(initialOffset);
XmlDictionaryWriter writer = TakeXmlWriter(_stream);
OnWriteStartMessage(writer);
message.WriteMessage(writer);
OnWriteEndMessage(writer);
writer.Flush();
ReturnXmlWriter(writer);
int size;
byte[] buffer = _stream.ToArray(out size);
RecordActualMessageSize(size);
return new ArraySegment<byte>(buffer, initialOffset, size - initialOffset);
}
finally
{
_stream.Clear();
}
}
示例14: WriteMessage
public ArraySegment<byte> WriteMessage(MessageEncoder encoder, Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
{
MemoryStream stream = new MemoryStream();
StreamWriter sw = new StreamWriter(stream);
string methodName = null;
if (message.Properties.ContainsKey(JSONPBehavior.Name))
{
methodName = ((JSONPMessageProperty) (message.Properties[JSONPBehavior.Name])).MethodName;
}
if (methodName != null)
{
sw.Write(methodName + "( ");
sw.Flush();
}
XmlWriter writer = JsonReaderWriterFactory.CreateJsonWriter(stream);
message.WriteMessage(writer);
writer.Flush();
if (methodName != null)
{
sw.Write(" );");
sw.Flush();
}
byte[] messageBytes = stream.GetBuffer();
int messageLength = (int) stream.Position;
int totalLength = messageLength + messageOffset;
byte[] totalBytes = bufferManager.TakeBuffer(totalLength);
Array.Copy(messageBytes, 0, totalBytes, messageOffset, messageLength);
ArraySegment<byte> byteArray = new ArraySegment<byte>(totalBytes, messageOffset, messageLength);
writer.Close();
return byteArray;
}
示例15: LogMessage
private void LogMessage(string messageType, Message message)
{
var writerSettings = new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = false };
using (var memoryStream = new MemoryStream())
{
using (var writer = XmlDictionaryWriter.Create(memoryStream, writerSettings))
{
message.WriteMessage(writer);
writer.Flush();
var size = Math.Round(memoryStream.Position/1024d, 2);
logger.InfoFormat("{0} message size: ~{1} KB", messageType, size);
}
if (messageLogger.IsDebugEnabled)
{
memoryStream.Position = 0;
using (var reader = new StreamReader(memoryStream))
{
messageLogger.Debug(reader.ReadToEnd());
}
}
}
}