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); } base.ThrowIfMismatchedMessageVersion(message); message.Properties.Encoder = this; XmlDictionaryWriter writer = this.TakeStreamedWriter(stream); if (this.optimizeWriteForUTF8) { message.WriteMessage(writer); } else { writer.WriteStartDocument(); message.WriteMessage(writer); writer.WriteEndDocument(); } writer.Flush(); this.ReturnStreamedWriter(writer); 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); }
public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState) { if (correlationState != null && String.Equals(correlationState, _correlationState) && !reply.ToString().Contains("<soapenv:Fault>")) { var memoryStream = new MemoryStream(); var writer = XmlWriter.Create(memoryStream); reply.WriteMessage(writer); writer.Flush(); memoryStream.Position = 0; var doc = new XmlDocument(); doc.Load(memoryStream); UpdateMessage(doc); memoryStream.SetLength(0); writer = XmlWriter.Create(memoryStream); doc.WriteTo(writer); writer.Flush(); memoryStream.Position = 0; var reader = XmlReader.Create(memoryStream); reply = Message.CreateMessage(reader, int.MaxValue, reply.Version); } }
public override void WriteMessage(Message message, Stream stream) { VerifyMessageVersion(message); using (var xw = XmlDictionaryWriter.CreateBinaryWriter(stream, Constants.SoapDictionary, session ? CurrentWriterSession : null)) message.WriteMessage(xw); }
/// <summary> /// Enables inspection or modification of a message before a request message is sent to a service. /// </summary> /// <returns> /// The object that is returned as the <paramref name="correlationState "/>argument of the <see cref="M:System.ServiceModel.Dispatcher.IClientMessageInspector.AfterReceiveReply(System.ServiceModel.Channels.Message@,System.Object)"/> method. This is null if no correlation state is used.The best practice is to make this a <see cref="T:System.Guid"/> to ensure that no two <paramref name="correlationState"/> objects are the same. /// </returns> /// <param name="request">The message to be sent to the service.</param><param name="channel">The WCF client object channel.</param> public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel) { XmlDocument doc = new XmlDocument(); MemoryStream ms = new MemoryStream(); using (XmlWriter writer = XmlWriter.Create(ms)) { request.WriteMessage(writer); } ms.Position = 0; doc.Load(ms); Trace.TraceInformation("RicohEmbeddedMessageInspector.BeforeSendRequest INCOMING={0}", doc.OuterXml); FixEmbeddedMessageBody(doc); Trace.TraceInformation("RicohEmbeddedMessageInspector.BeforeSendRequest OUTGOING={0}", doc.OuterXml); ms.SetLength(0); using (XmlWriter writer = XmlWriter.Create(ms)) { doc.WriteTo(writer); } ms.Position = 0; XmlReader reader = XmlReader.Create(ms); request = Message.CreateMessage(reader, int.MaxValue, request.Version); return(null); }
public override void WriteMessage(Message message, Stream stream) { VerifyMessageVersion(message); // FIXME: no way to acquire maxSizeInBytes and startInfo? message.WriteMessage(XmlDictionaryWriter.CreateMtomWriter(stream, encoding, int.MaxValue, null)); }
private static Message TraceOutMessage(System.ServiceModel.Channels.Message request, HttpRequestMessageProperty httpRequestMessageProperty) { var messageBuffer = request.CreateBufferedCopy(Int32.MaxValue); request = messageBuffer.CreateMessage(); if (httpRequestMessageProperty != null) { var url = (request.Headers).To.OriginalString; Console.WriteLine("URI: " + url); Console.WriteLine("Method: " + httpRequestMessageProperty.Method); } StringBuilder sb = new StringBuilder(); using (System.IO.TextWriter tw = new System.IO.StringWriter(sb)) { using (System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(tw)) { xw.Formatting = System.Xml.Formatting.Indented; request.WriteMessage(xw); } } Console.WriteLine(sb.ToString()); Console.WriteLine(); request = messageBuffer.CreateMessage(); return(request); }
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); } }
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)); } }
private void WriteMessage(System.ServiceModel.Channels.Message message) { using (var stringWriter = new StringWriter()) { using (var xmlWriter = new XmlTextWriter(stringWriter)) { xmlWriter.Formatting = Formatting.Indented; message.WriteMessage(xmlWriter); Output.SetText(stringWriter.ToString()); } } }
public string GetMessageEnvelope(Message msg) { var sb = new StringBuilder(); using (var sw = XmlWriter.Create(new StringWriter(sb))) { msg.WriteMessage(sw); sw.Flush(); return(sb.ToString()); } }
public override void WriteMessage(System.ServiceModel.Channels.Message message, Stream stream) { if (ShouldWriteMtom(message)) { XmlDictionaryWriter mtomWriter = CreateMtomWriter(stream, message); message.WriteMessage(mtomWriter); } else { _textEncoder.WriteMessage(message, stream); } }
public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel, InstanceContext instanceContext) { object messageProperty; if (!OperationContext.Current.IncomingMessageProperties.TryGetValue(RemoteEndpointMessageProperty.Name, out messageProperty)) { return(null); } var remoteEndpointProperty = messageProperty as RemoteEndpointMessageProperty; if (remoteEndpointProperty == null) { return(null); } // Extract message body string messageBody; using (var oldMessageStream = new MemoryStream()) { using (var xw = XmlWriter.Create(oldMessageStream)) { request.WriteMessage(xw); xw.Flush(); messageBody = Encoding.UTF8.GetString(oldMessageStream.ToArray()); } } // Replace instances of 0.0.0.0 with actual remote endpoint address var remoteAddr = remoteEndpointProperty.Address; var remotePort = remoteEndpointProperty.Port; var remoteEndpoint = remoteAddr + ":" + remotePort; // messageBody = messageBody.Replace("0.0.0.0:0", remoteEndpoint); messageBody = messageBody.Replace("0.0.0.0", remoteEndpointProperty.Address); // NOTE: Do not close or dispose of this MemoryStream. It will be used by WCF down the line. var newMessageStream = new MemoryStream(Encoding.UTF8.GetBytes(messageBody)); XmlDictionaryReader xdr = XmlDictionaryReader.CreateTextReader(newMessageStream, new XmlDictionaryReaderQuotas()); // Create a new message with our modified endpoint address and // copy over existing properties and headers System.ServiceModel.Channels.Message newMessage = System.ServiceModel.Channels.Message.CreateMessage(xdr, int.MaxValue, request.Version); newMessage.Properties.CopyProperties(request.Properties); newMessage.Headers.CopyHeadersFrom(request.Headers); request = newMessage; return(null); }
public virtual void WriteMessage(Stream stream) { if (stream == null) { throw new ArgumentNullException("stream is null"); } XmlDictionaryWriter w = XmlDictionaryWriter.CreateBinaryWriter(stream); Message m = CreateMessage(); m.WriteMessage(w); w.Close(); }
/// <summary> /// This method removes the empty tags from the soap request before sending the request to the server. /// </summary> /// <param name="request"></param> /// <param name="channel"></param> /// <returns></returns> public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel) { MemoryStream memoryStream = new MemoryStream(); XmlWriter xmlWriter = XmlWriter.Create(memoryStream); request.WriteMessage(xmlWriter); xmlWriter.Flush(); memoryStream.Position = 0; XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(memoryStream); XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xmlDocument.NameTable); xmlNamespaceManager.AddNamespace("env", "http://schemas.xmlsoap.org/soap/envelope/"); XmlNode header = xmlDocument.SelectSingleNode("//env:Header", xmlNamespaceManager); if (header != null) { header.ParentNode.RemoveChild(header); } XmlNodeList nodes = xmlDocument.SelectNodes("//node()"); foreach (XmlNode node in nodes) { if (node.NodeType == XmlNodeType.Element && node.ChildNodes.Count == 0 && node.InnerXml == "") { node.ParentNode.RemoveChild(node); } } memoryStream = new MemoryStream(); xmlDocument.Save(memoryStream); memoryStream.Position = 0; XmlReader xmlReader = XmlReader.Create(memoryStream); System.ServiceModel.Channels.Message newMessage = System.ServiceModel.Channels.Message.CreateMessage(xmlReader, int.MaxValue, request.Version); newMessage.Headers.CopyHeadersFrom(request.Headers); newMessage.Properties.CopyProperties(request.Properties); //Logging processed request MessageBuffer buffer = newMessage.CreateBufferedCopy(Int32.MaxValue); newMessage = buffer.CreateMessage(); LogRequestResponse(buffer, "Opportunity Service Request"); request = newMessage; return(request); }
/// <summary> /// Convert a Message to XMLDocument /// </summary> /// <param name="msg">Message to convert</param> /// <returns></returns> public static XmlDocument MessageToXDom(System.ServiceModel.Channels.Message msg) { XmlDocument doc = new XmlDocument(); MemoryStream ms = new MemoryStream(); XmlWriter writer = XmlWriter.Create(ms); msg.WriteMessage(writer); writer.Flush(); ms.Position = 0; doc.Load(ms); return(doc); }
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(); } }
public virtual void WriteMessage(Stream stream) { if (stream == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("stream")); } Message message = this.CreateMessage(); using (message) { XmlDictionaryWriter writer = XmlDictionaryWriter.CreateBinaryWriter(stream, XD.Dictionary, null, false); using (writer) { message.WriteMessage(writer); } } }
private XmlDocument GetDocument(System.ServiceModel.Channels.Message request) { XmlDocument document = new XmlDocument(); using (MemoryStream memoryStream = new MemoryStream()) using (XmlWriter writer = XmlWriter.Create(memoryStream)) { // write request to memory stream request.WriteMessage(writer); writer.Flush(); memoryStream.Position = 0; // load memory stream into a document document.Load(memoryStream); } return(document); }
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); }
public override ArraySegment <byte> WriteMessage( Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset) { VerifyMessageVersion(message); ArraySegment <byte> seg = new ArraySegment <byte> ( bufferManager.TakeBuffer(maxMessageSize), messageOffset, maxMessageSize); XmlWriterSettings s = new XmlWriterSettings(); s.Encoding = encoding; using (XmlWriter w = XmlWriter.Create( new MemoryStream(seg.Array, seg.Offset, seg.Count), s)) { message.WriteMessage( XmlDictionaryWriter.CreateDictionaryWriter(w)); } return(seg); }
public override ArraySegment <byte> WriteMessage(System.ServiceModel.Channels.Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset) { if (this.ShouldWriteMtom(message)) { using (MemoryStream ms = new MemoryStream()) { XmlDictionaryWriter mtomWriter = CreateMtomWriter(ms, message); message.WriteMessage(mtomWriter); mtomWriter.Flush(); byte[] buffer = bufferManager.TakeBuffer((int)ms.Position + messageOffset); Array.Copy(ms.GetBuffer(), 0, buffer, messageOffset, (int)ms.Position); return(new ArraySegment <byte>(buffer, messageOffset, (int)ms.Position)); } } else { return(this._textEncoder.WriteMessage(message, maxMessageSize, bufferManager, messageOffset)); } }
/// <summary> /// Write Message to the string /// </summary> /// <param name="message"></param> /// <returns></returns> public static string WriteToString(this System.ServiceModel.Channels.Message message) { StringBuilder sb = new StringBuilder(); XmlWriterSettings settings = new XmlWriterSettings() { OmitXmlDeclaration = true, Indent = true, Encoding = UTF8Encoding.UTF8 }; using (XmlDictionaryWriter dwr = XmlDictionaryWriter.CreateDictionaryWriter(XmlDictionaryWriter.Create(sb, settings))) { dwr.WriteStartDocument(); message.WriteMessage(dwr); dwr.WriteEndDocument(); dwr.Flush(); } return(sb.ToString()); }
public override void WriteMessage(Message message, Stream stream) { if (message == null) { throw new ArgumentNullException("message"); } if (stream == null) { throw new ArgumentNullException("stream"); } VerifyMessageVersion(message); XmlWriterSettings s = new XmlWriterSettings(); s.Encoding = encoding; using (XmlWriter w = XmlWriter.Create(stream, s)) { message.WriteMessage( XmlDictionaryWriter.CreateDictionaryWriter(w)); } }
public static XDocument ReadWcfMessageBuffer(ref ServiceModelChannels.Message message) { using (ServiceModelChannels.MessageBuffer msgbuf = message.CreateBufferedCopy(int.MaxValue)) { ServiceModelChannels.Message messageCopy = msgbuf.CreateMessage(); using (MemoryStream stream = new MemoryStream()) { using (XmlWriter writer = XmlWriter.Create(stream)) { messageCopy.WriteMessage(writer); writer.Flush(); stream.Position = 0; XDocument xdoc = XDocument.Load(XmlReader.Create(stream)); message = msgbuf.CreateMessage(); return(xdoc); } } } }
/// <summary> /// This will parse the response received from the service and remove all empty elements from it /// </summary> public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState) { MemoryStream memoryStream = new MemoryStream(); XmlWriter xmlWriter = XmlWriter.Create(memoryStream); reply.WriteMessage(xmlWriter); xmlWriter.Flush(); memoryStream.Position = 0; XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(memoryStream); XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xmlDocument.NameTable); xmlNamespaceManager.AddNamespace("env", "http://schemas.xmlsoap.org/soap/envelope/"); XmlNode header = xmlDocument.SelectSingleNode("//env:Header", xmlNamespaceManager); if (header != null) { header.ParentNode.RemoveChild(header); } XmlNodeList nodes = xmlDocument.SelectNodes("//node()"); foreach (XmlNode node in nodes) { if (node.NodeType == XmlNodeType.Element && node.ChildNodes.Count == 0 && node.InnerXml == "" && node.Attributes.Count == 0) { node.ParentNode.RemoveChild(node); } } memoryStream = new MemoryStream(); xmlDocument.Save(memoryStream); memoryStream.Position = 0; XmlReader xmlReader = XmlReader.Create(memoryStream); System.ServiceModel.Channels.Message newMessage = System.ServiceModel.Channels.Message.CreateMessage(xmlReader, int.MaxValue, reply.Version); newMessage.Headers.CopyHeadersFrom(reply.Headers); newMessage.Properties.CopyProperties(reply.Properties); reply = newMessage; }
/// <summary> /// Convert the message to a string. /// </summary> /// <param name="msg">Message to convert.</param> /// <returns>Message as a string.</returns> private string ConvertMessageToString(System.ServiceModel.Channels.Message msg) { var ms = new MemoryStream(); var xw = XmlTextWriter.Create(ms, new XmlWriterSettings() { Indent = false, OmitXmlDeclaration = true }); msg.WriteMessage(xw); xw.Close(); ms.Position = 0; var sr = new StreamReader(ms); var convertedString = sr.ReadToEnd(); sr.Close(); ms.Close(); return(convertedString); }
public override void WriteMessage(Message message, Stream stream) { if (message == null) { throw FxTrace.Exception.ArgumentNull("message"); } if (stream == null) { throw FxTrace.Exception.ArgumentNull("stream"); } ThrowIfMismatchedMessageVersion(message); EventTraceActivity eventTraceActivity = null; if (TD.ByteStreamMessageEncodingStartIsEnabled()) { eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message); TD.ByteStreamMessageEncodingStart(eventTraceActivity); } message.Properties.Encoder = this; if (MessageLogger.LogMessagesAtTransportLevel) { MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportSend); } using (XmlWriter writer = new XmlByteStreamWriter(stream, false)) { message.WriteMessage(writer); writer.Flush(); } if (SMTD.StreamedMessageWrittenByEncoderIsEnabled()) { SMTD.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); message.Properties.Encoder = this; XmlDictionaryWriter xmlWriter = CreateWriter(stream); xmlWriter.WriteStartDocument(); message.WriteMessage(xmlWriter); xmlWriter.WriteEndDocument(); xmlWriter.Flush(); xmlWriter.Close(); if (MessageLogger.LogMessagesAtTransportLevel) { MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportSend); } }
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); } }
public string GetMessageEnvelope(Message msg) { var sb = new StringBuilder(); using (var sw = XmlWriter.Create(new StringWriter(sb))) { msg.WriteMessage(sw); sw.Flush(); return sb.ToString(); } }