void WriteHeader(XmlDictionaryWriter dictionaryWriter) { dictionaryWriter.WriteStartElement(XD.MessageDictionary.Prefix.Value, XD.MessageDictionary.Header, this.message.Version.Envelope.DictionaryNamespace); MessageHeaders headers = this.message.Headers; Security.ReceiveSecurityHeader receivedHeader = null; if (this.message is SecurityVerifiedMessage) { SecurityVerifiedMessage verifiedMessage = this.message as SecurityVerifiedMessage; receivedHeader = verifiedMessage.ReceivedSecurityHeader; } for (int i = 0; i < headers.Count; ++i) { if (receivedHeader != null && receivedHeader.HasAtLeastOneItemInsideSecurityHeaderEncrypted && receivedHeader.HeaderIndex == i) { // // if this is the security header and we found at least one item // was encrypted inside the security header // receivedHeader.WriteStartHeader(dictionaryWriter, headers.MessageVersion); receivedHeader.WriteHeaderContents(dictionaryWriter, headers.MessageVersion); dictionaryWriter.WriteEndElement(); } else { headers.WriteHeader(i, dictionaryWriter); } } dictionaryWriter.WriteEndElement(); // </Headers> }
private void WriteHeader(XmlDictionaryWriter dictionaryWriter) { dictionaryWriter.WriteStartElement(XD.MessageDictionary.Prefix.Value, XD.MessageDictionary.Header, this.message.Version.Envelope.DictionaryNamespace); MessageHeaders headers = this.message.Headers; ReceiveSecurityHeader receivedSecurityHeader = null; if (this.message is SecurityVerifiedMessage) { SecurityVerifiedMessage message = this.message as SecurityVerifiedMessage; receivedSecurityHeader = message.ReceivedSecurityHeader; } for (int i = 0; i < headers.Count; i++) { if (((receivedSecurityHeader != null) && receivedSecurityHeader.HasAtLeastOneItemInsideSecurityHeaderEncrypted) && (receivedSecurityHeader.HeaderIndex == i)) { receivedSecurityHeader.WriteStartHeader(dictionaryWriter, headers.MessageVersion); receivedSecurityHeader.WriteHeaderContents(dictionaryWriter, headers.MessageVersion); dictionaryWriter.WriteEndElement(); } else { headers.WriteHeader(i, dictionaryWriter); } } dictionaryWriter.WriteEndElement(); }
internal override void WriteTo(XmlWriter writer) { writer.WriteStartElement(MessageLogTraceRecord.NamespacePrefix, MessageLogTraceRecord.MessageLogTraceRecordElementName, MessageLogTraceRecord.NamespaceUri); // <MessageLogTraceRecord> writer.WriteAttributeString(MessageLogTraceRecord.TraceTimeAttributeName, this.timestamp.ToString("o", CultureInfo.InvariantCulture)); writer.WriteAttributeString(DiagnosticStrings.SourceTag, this.source.ToString()); if (null != this.type) { Fx.Assert(this.message != null, ""); XmlDictionaryWriter dictionaryWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer); dictionaryWriter.WriteAttributeString(MessageLogTraceRecord.TypeElementName, this.type.ToString()); #if DEBUG MessageProperties properties = this.message.Properties; dictionaryWriter.WriteStartElement("Properties"); foreach (string key in properties.Keys) { dictionaryWriter.WriteElementString(key, properties[key].ToString()); } dictionaryWriter.WriteEndElement(); // </Properties> #endif WriteAddressingProperties(dictionaryWriter); WriteHttpProperties(dictionaryWriter); if (null != this.reader) //TransportSend case: Message may miss some security data, so we use XmlReader created from serialized message { this.reader.MoveToContent(); } if (this.logMessageBody) { if (null != this.reader) { dictionaryWriter.WriteNode(this.reader, true); } else { bool hasAtLeastOneItemInsideSecurityHeaderEncrypted = false; if (this.message is SecurityVerifiedMessage) { SecurityVerifiedMessage verifiedMessage = this.message as SecurityVerifiedMessage; ReceiveSecurityHeader receivedHeader = verifiedMessage.ReceivedSecurityHeader; hasAtLeastOneItemInsideSecurityHeaderEncrypted = receivedHeader.HasAtLeastOneItemInsideSecurityHeaderEncrypted; } if (!hasAtLeastOneItemInsideSecurityHeaderEncrypted) { this.message.ToString(dictionaryWriter); } else { if (this.message.Version.Envelope != EnvelopeVersion.None) { dictionaryWriter.WriteStartElement(XD.MessageDictionary.Prefix.Value, XD.MessageDictionary.Envelope, this.message.Version.Envelope.DictionaryNamespace); WriteHeader(dictionaryWriter); this.message.WriteStartBody(writer); } this.message.BodyToString(dictionaryWriter); if (this.message.Version.Envelope != EnvelopeVersion.None) { writer.WriteEndElement(); // </Body> dictionaryWriter.WriteEndElement(); // </Envelope> } } } } else if (this.message.Version.Envelope != EnvelopeVersion.None) //No headers for EnvelopeVersion.None { if (null != this.reader) { dictionaryWriter.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI); this.reader.Read(); if (0 == String.CompareOrdinal(reader.LocalName, "Header")) { dictionaryWriter.WriteNode(this.reader, true); } dictionaryWriter.WriteEndElement(); } else { dictionaryWriter.WriteStartElement(XD.MessageDictionary.Prefix.Value, XD.MessageDictionary.Envelope, this.message.Version.Envelope.DictionaryNamespace); WriteHeader(dictionaryWriter); dictionaryWriter.WriteEndElement(); // </Envelope> } } if (null != this.reader) { this.reader.Close(); this.reader = null; } } else { writer.WriteCData(this.messageString); } writer.WriteEndElement(); // </MessageLogTraceRecord> }
internal override void WriteTo(XmlWriter writer) { writer.WriteStartElement("", "MessageLogTraceRecord", "http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace"); writer.WriteAttributeString("Time", this.timestamp.ToString("o", CultureInfo.InvariantCulture)); writer.WriteAttributeString("Source", this.source.ToString()); if (null != this.type) { XmlDictionaryWriter dictionaryWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer); dictionaryWriter.WriteAttributeString("Type", this.type.ToString()); this.WriteAddressingProperties(dictionaryWriter); this.WriteHttpProperties(dictionaryWriter); if (this.reader != null) { this.reader.MoveToContent(); } if (this.logMessageBody) { if (this.reader != null) { dictionaryWriter.WriteNode(this.reader, true); } else { bool hasAtLeastOneItemInsideSecurityHeaderEncrypted = false; if (this.message is SecurityVerifiedMessage) { SecurityVerifiedMessage message = this.message as SecurityVerifiedMessage; hasAtLeastOneItemInsideSecurityHeaderEncrypted = message.ReceivedSecurityHeader.HasAtLeastOneItemInsideSecurityHeaderEncrypted; } if (!hasAtLeastOneItemInsideSecurityHeaderEncrypted) { this.message.ToString(dictionaryWriter); } else { if (this.message.Version.Envelope != EnvelopeVersion.None) { dictionaryWriter.WriteStartElement(XD.MessageDictionary.Prefix.Value, XD.MessageDictionary.Envelope, this.message.Version.Envelope.DictionaryNamespace); this.WriteHeader(dictionaryWriter); this.message.WriteStartBody(writer); } this.message.BodyToString(dictionaryWriter); if (this.message.Version.Envelope != EnvelopeVersion.None) { writer.WriteEndElement(); dictionaryWriter.WriteEndElement(); } } } } else if (this.message.Version.Envelope != EnvelopeVersion.None) { if (this.reader != null) { dictionaryWriter.WriteStartElement(this.reader.Prefix, this.reader.LocalName, this.reader.NamespaceURI); this.reader.Read(); if (string.CompareOrdinal(this.reader.LocalName, "Header") == 0) { dictionaryWriter.WriteNode(this.reader, true); } dictionaryWriter.WriteEndElement(); } else { dictionaryWriter.WriteStartElement(XD.MessageDictionary.Prefix.Value, XD.MessageDictionary.Envelope, this.message.Version.Envelope.DictionaryNamespace); this.WriteHeader(dictionaryWriter); dictionaryWriter.WriteEndElement(); } } if (this.reader != null) { this.reader.Close(); this.reader = null; } } else { writer.WriteCData(this.messageString); } writer.WriteEndElement(); }