Ejemplo n.º 1
0
		public static string GetSerializedMessage (Message msg)
		{
			StringWriter sw = new StringWriter ();
			XmlWriterSettings settings = new XmlWriterSettings ();
			settings.OmitXmlDeclaration = true;
			using (XmlWriter xw = XmlWriter.Create (sw, settings)) {
				msg.WriteMessage (xw);
			}
			return sw.ToString ();
		}
Ejemplo n.º 2
0
            public override void WriteMessage(Message message, Stream stream)
            {
                if (message == null)
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("message"));
                if (stream == null)
                    throw TraceUtility.ThrowHelperError(new ArgumentNullException("stream"), message);
                ThrowIfMismatchedMessageVersion(message);

                EventTraceActivity eventTraceActivity = null;
                if (TD.TextMessageEncodingStartIsEnabled())
                {
                    eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message);
                    TD.TextMessageEncodingStart(eventTraceActivity);
                }

                message.Properties.Encoder = this;
                XmlDictionaryWriter xmlWriter = TakeStreamedWriter(stream);
                if (optimizeWriteForUTF8)
                {
                    message.WriteMessage(xmlWriter);
                }
                else
                {
                    xmlWriter.WriteStartDocument();
                    message.WriteMessage(xmlWriter);
                    xmlWriter.WriteEndDocument();
                }
                xmlWriter.Flush();
                ReturnStreamedWriter(xmlWriter);

                if (TD.StreamedMessageWrittenByEncoderIsEnabled())
                {
                    TD.StreamedMessageWrittenByEncoder(eventTraceActivity ?? EventTraceActivityHelper.TryExtractActivity(message));
                }

                if (MessageLogger.LogMessagesAtTransportLevel)
                    MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportSend);
            }
Ejemplo n.º 3
0
        void WriteMessage(Message message, Stream stream, string startInfo, string boundary, string startUri, bool writeMessageHeaders)
        {
            if (message == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("message"));
            if (stream == null)
                throw TraceUtility.ThrowHelperError(new ArgumentNullException("stream"), message);
            ThrowIfMismatchedMessageVersion(message);

            EventTraceActivity eventTraceActivity = null;
            if (TD.MtomMessageEncodingStartIsEnabled())
            {
                eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message);
                TD.MtomMessageEncodingStart(eventTraceActivity);
            }

            message.Properties.Encoder = this;
            if (MessageLogger.LogMessagesAtTransportLevel)
                MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportSend);
            XmlDictionaryWriter xmlWriter = TakeStreamedWriter(stream, startInfo, boundary, startUri, writeMessageHeaders);
            if (this.writeEncoding.WebName == "utf-8")
            {
                message.WriteMessage(xmlWriter);
            }
            else
            {
                xmlWriter.WriteStartDocument();
                message.WriteMessage(xmlWriter);
                xmlWriter.WriteEndDocument();
            }
            xmlWriter.Flush();
            ReturnStreamedWriter(xmlWriter);

            if (TD.StreamedMessageWrittenByEncoderIsEnabled())
            {
                TD.StreamedMessageWrittenByEncoder(eventTraceActivity ?? EventTraceActivityHelper.TryExtractActivity(message));
            }
        }
            public override void WriteMessage(Message message, Stream stream)
            {
                if (message == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("message"));
                }
                if (stream == null)
                {
                    throw TraceUtility.ThrowHelperError(new ArgumentNullException("stream"), message);
                }
                ThrowIfMismatchedMessageVersion(message);

                EventTraceActivity eventTraceActivity = null;
                if (WebTD.JsonMessageEncodingStartIsEnabled())
                {
                    eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message);
                    WebTD.JsonMessageEncodingStart(eventTraceActivity);
                }

                message.Properties.Encoder = this;
                XmlDictionaryWriter xmlWriter = TakeStreamedWriter(stream);
                JavascriptCallbackResponseMessageProperty javascriptResponseMessageProperty;
                if (message.Properties.TryGetValue<JavascriptCallbackResponseMessageProperty>(JavascriptCallbackResponseMessageProperty.Name, out javascriptResponseMessageProperty)
                    && javascriptResponseMessageProperty != null
                    && !String.IsNullOrEmpty(javascriptResponseMessageProperty.CallbackFunctionName))
                {
                    if (!this.crossDomainScriptAccessEnabled)
                    {
                        throw TraceUtility.ThrowHelperError(new InvalidOperationException(SR2.JavascriptCallbackNotEnabled), message);
                    }
                    byte[] buffer = this.writeEncoding.GetBytes(String.Format(CultureInfo.InvariantCulture, "{0}(", javascriptResponseMessageProperty.CallbackFunctionName));
                    stream.Write(buffer, 0, buffer.Length);
                }
                xmlWriter.WriteStartDocument();
                message.WriteMessage(xmlWriter);
                xmlWriter.WriteEndDocument();
                xmlWriter.Flush();
                ReturnStreamedWriter(xmlWriter);
                if (javascriptResponseMessageProperty != null
                    && !String.IsNullOrEmpty(javascriptResponseMessageProperty.CallbackFunctionName))
                {
                    if (javascriptResponseMessageProperty.StatusCode != null && (int)javascriptResponseMessageProperty.StatusCode != 200)
                    {
                        byte[] buffer = this.writeEncoding.GetBytes(String.Format(CultureInfo.InvariantCulture, ",{0}", (int)javascriptResponseMessageProperty.StatusCode));
                        stream.Write(buffer, 0, buffer.Length);
                    }
                    stream.Write(this.encodedClosingFunctionCall, 0, this.encodedClosingFunctionCall.Length);
                }

                if (SMTD.StreamedMessageWrittenByEncoderIsEnabled())
                {
                    SMTD.StreamedMessageWrittenByEncoder(
                        eventTraceActivity ?? EventTraceActivityHelper.TryExtractActivity(message));
                }

                if (MessageLogger.LogMessagesAtTransportLevel)
                {
                    MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportSend);
                }
            }
 private void WriteMessage(Message message, Stream stream, string startInfo, string boundary, string startUri, bool writeMessageHeaders)
 {
     if (message == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("message"));
     }
     if (stream == null)
     {
         throw TraceUtility.ThrowHelperError(new ArgumentNullException("stream"), message);
     }
     base.ThrowIfMismatchedMessageVersion(message);
     message.Properties.Encoder = this;
     if (MessageLogger.LogMessagesAtTransportLevel)
     {
         MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportSend);
     }
     XmlDictionaryWriter writer = this.TakeStreamedWriter(stream, startInfo, boundary, startUri, writeMessageHeaders);
     if (this.writeEncoding.WebName == "utf-8")
     {
         message.WriteMessage(writer);
     }
     else
     {
         writer.WriteStartDocument();
         message.WriteMessage(writer);
         writer.WriteEndDocument();
     }
     writer.Flush();
     this.ReturnStreamedWriter(writer);
 }