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


C# Message.WriteMessage方法代码示例

本文整理汇总了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();
			}
		}
开发者ID:ralescano,项目名称:castle,代码行数:29,代码来源:CustomMessageFormatter.cs

示例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;
        }
开发者ID:vendettamit,项目名称:PatternsFun,代码行数:33,代码来源:IncomingMessageLogger.cs

示例3: Echo

	public Message Echo (Message msg) 
	{
		using (XmlWriter w = XmlWriter.Create (Console.Out)) {
			msg.WriteMessage (w);
		}
		throw new NotImplementedException ("you are here.");
	}
开发者ID:alesliehughes,项目名称:olive,代码行数:7,代码来源:samplesvc.cs

示例4: WriteMessage

 public override void WriteMessage(Message message, Stream stream)
 {
     using (XmlWriter writer = XmlWriter.Create(stream, _writerSettings))
     {
         message.WriteMessage(writer);
     }
 }
开发者ID:weshaggard,项目名称:wcf,代码行数:7,代码来源:CustomTextMessageEncoder.cs

示例5: WriteMessage

 static void WriteMessage(Message message, string fileName)
 {
     using (XmlWriter writer = new XmlTextWriter(fileName, Encoding.UTF8))
     {
         message.WriteMessage(writer);
     }
     Process.Start(fileName);
 }
开发者ID:huoxudong125,项目名称:WCF-Demo,代码行数:8,代码来源:Program.cs

示例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());
 }
开发者ID:riyaan,项目名称:konica,代码行数:10,代码来源:LogInspector.cs

示例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);
     }
 }
开发者ID:gobixm,项目名称:learn,代码行数:12,代码来源:JsonMessageSerializer.cs

示例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);
         }
     }
 }
开发者ID:XerMajor,项目名称:Shamsullin,代码行数:12,代码来源:WcfRestBehavior.cs

示例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;
			}
		}
开发者ID:CarverLab,项目名称:tubeCoreWebService.root,代码行数:13,代码来源:ActivityMessageFilter.cs

示例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;
        }
开发者ID:marinoscar,项目名称:WeatherService,代码行数:18,代码来源:IsoTextMessageEncoder.cs

示例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;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:42,代码来源:BufferedMessageWriter.cs

示例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;
        }
开发者ID:yoshiao,项目名称:WCF_Samples,代码行数:20,代码来源:CustomEncoder.cs

示例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();
            }
        }
开发者ID:weshaggard,项目名称:wcf,代码行数:38,代码来源:BufferedMessageWriter.cs

示例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;
        }
开发者ID:apavlo11356,项目名称:adamdotcom-services,代码行数:37,代码来源:JSONPEncoder.cs

示例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());
                    }
                }
            }
        }
开发者ID:hoghweed,项目名称:Agatha,代码行数:24,代码来源:MessageInspector.cs


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