/// <summary> /// Process a message log trace record. /// </summary> /// <returns>The parsed message, or null if the message had no body.</returns> private ParsedMessage ProcessMessageLogTraceRecord() { ParsedMessage ans = null; DateTime timestamp = DateTime.MinValue; if (this.reader.MoveToAttribute(TimeAttributeName)) { timestamp = DateTime.Parse(this.reader.Value, CultureInfo.InvariantCulture); } // Move to next element. Service side trace contains a HttpRequest node, if present skip this while (this.reader.Read() && this.reader.NodeType != XmlNodeType.Element) { } ////this._reader.Skip(); if (this.reader.Name == HttpRequestElementName) { this.reader.Skip(); } MessageVersion messageVersion = GetMessageVersion(this.reader); XmlReader envelopeReader = this.reader.ReadSubtree(); Message tempMessage = null; try { using (tempMessage = Message.CreateMessage(envelopeReader, int.MaxValue, messageVersion)) { string soapAction = GetSoapAction(tempMessage); ans = new ParsedMessage(tempMessage.CreateBufferedCopy(int.MaxValue), soapAction, timestamp); } } catch (CommunicationException) { // ignore if no body and just return null } finally { envelopeReader.Close(); } return(ans); }
/// <summary> /// Reads the next valid request message from the trace file. /// </summary> /// <remarks> /// This method does some initial filtering. /// </remarks> /// <returns>The next request message from the trace file.</returns> protected override ParsedMessage ReadNextMessageCore() { ParsedMessage ans = null; string line; while ((line = this.textReader.ReadLine()) != null) { string soapAction = null; if ((soapAction = CheckLineForSoapAction(line)) != null) { this.ReadToAfterNextBlankLine(); XmlReaderSettings settings = new XmlReaderSettings(); settings.CloseInput = false; settings.ConformanceLevel = ConformanceLevel.Fragment; settings.IgnoreWhitespace = true; using (XmlReader envelopeReader = XmlReader.Create(this.textReader, settings)) { envelopeReader.MoveToContent(); MessageVersion messageVersion = GetMessageVersion(envelopeReader); using (Message tempMessage = Message.CreateMessage(envelopeReader.ReadSubtree(), int.MaxValue, messageVersion)) { Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Read message with soap action = {0}", tempMessage.Headers.Action)); ans = new ParsedMessage(tempMessage.CreateBufferedCopy(int.MaxValue), soapAction, DateTime.MinValue); } } // Read and discard the response this.ReadToAfterNextBlankLine(); // reader is positioned at EOL so looks like a blank line when it isn't this.ReadToAfterNextBlankLine(); using (XmlReader envelopeReader = XmlReader.Create(this.textReader, settings)) { envelopeReader.MoveToContent(); envelopeReader.ReadOuterXml(); } break; } } return(ans); }
/// <summary> /// Reads the next valid request message from the trace file. /// </summary> /// <remarks> /// This method does some initial filtering. WCF metadata exchange messages are filtered out here. /// </remarks> /// <returns>The next request message from the trace file.</returns> protected override ParsedMessage ReadNextMessageCore() { ParsedMessage ans = null; try { bool done = false; while (!done && !this.reader.EOF) { if (this.reader.Name != E2ETraceElementName && this.reader.NamespaceURI != E2ETraceNamespace) { this.ThrowInvalidMessageLog(null); } if (this.reader.ReadToFollowing(SourceElementName, SystemNamespace)) { if (this.reader.MoveToAttribute(NameAttributeName)) { if (this.reader.Value != MessageLoggingSourceName) { throw new UserException(string.Format(CultureInfo.CurrentCulture, Messages.Parser_TraceFileFound, this.FileName)); } } else { this.ThrowInvalidMessageLog(null); } } else { this.ThrowInvalidMessageLog(null); } if (this.reader.ReadToFollowing(MessageLogTraceRecordElementName, TraceNamespace)) { if (this.reader.MoveToAttribute(SourceAttributeName)) { if ((this.ClientTrace && clientSource.Contains(this.reader.Value)) || (this.ServiceTrace && serviceSource.Contains(this.reader.Value))) { if (this.reader.MoveToAttribute(TypeAttributeName)) { if (this.reader.Value != NullMessageType) { ParsedMessage temp = this.ProcessMessageLogTraceRecord(); if (temp == null || IsMessageToBeSelected(temp.SoapAction)) { done = true; ans = temp; } } } } } this.reader.ReadToFollowing(E2ETraceElementName, E2ETraceNamespace); } else { done = true; } } } catch (XmlException xe) { this.ThrowInvalidMessageLog(xe); } return(ans); }