Constructing XmlTextReader causes "Root element is missing" in BizTalk WCF Send Pipeline RRS feed

  • Question

  • I have a send pipeline, and trying to parse the data using XmlTextReader in order to pick out an element value for use in my context.

    public IBaseMessage Execute(BizTalkComp.IPipelineContext pContext, IBaseMessage pInMsg) { IBaseMessagePart bodyPart = pInMsg.BodyPart; IBaseMessageContext context = pInMsg.Context; //context.Write("OutboundTransportLocation", "", // context.Read("OutboundTransportLocation", "")); int bufferSize = 0x280; int thresholdSize = 0x100000; System.Diagnostics.EventLog.WriteEntry("LOGGER","Pipeline1"); Stream inboundStream = bodyPart.GetOriginalDataStream(); VirtualStream virtualStream = new VirtualStream(bufferSize, thresholdSize); ReadOnlySeekableStream readOnlySeekableStream = new ReadOnlySeekableStream(inboundStream, virtualStream, bufferSize); System.Diagnostics.EventLog.WriteEntry("LOGGER","Pipeline2"); XmlTextReader xmlTextReader = new XmlTextReader(readOnlySeekableStream); //comment-this-line-out and it works // string dbName = ParseXMLForDatabaseName(xmlTextReader); xmlTextReader.Close(); virtualStream.Close(); virtualStream.Dispose(); string dbName = "US......"; // temporary value to be be able to comment out the XmlTextReader System.Diagnostics.EventLog.WriteEntry("LOGGER", "Pipeline3b dbName=" + dbName); string regionSpecificURL = ""; string firstTwoCharsOfDBame = dbName.Substring(0, 2); switch (firstTwoCharsOfDBame) { case ("US"): regionSpecificURL = ""; break; case ("EM"): regionSpecificURL = ""; break; case ("AP"): regionSpecificURL = ""; break; default: regionSpecificURL = ""; break; } System.Diagnostics.EventLog.WriteEntry("LOGGER", "Pipeline4 regionSpecificURL=" + regionSpecificURL); // Three parms: 1) context proeprty, 2) context string namespace 3) value context.Promote( "OutboundTransportLocation", "", regionSpecificURL); context.Promote( "IsDynamicSend", "", true);

    System.Diagnostics.EventLog.WriteEntry("LOGGER","Pipeline5"); return pInMsg; }

    In this issue:,

    James Corbould gave me code that works to set the URL dynamically in a static send port.

    When I hardcode the URL, it works.  But now, when I need to parse the data, i get the following error when I use the XmlTextReader:

    System.Xml.XmlException: Root element is missing.
       at System.Xml.XmlTextReaderImpl.Throw(Exception e)
       at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
       at System.Xml.XmlTextReaderImpl.Read()
       at System.Xml.XmlReader.MoveToContent()
       at Microsoft.BizTalk.Adapter.Wcf.Runtime.BizTalkBodyWriter.ValidateStreamContainsXml(Stream stream)
       at Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfMarshaller.CreateWcfMessage(CreateWcfMessageSettings settings)
       at Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfClient`2.SendRequestMessage(IBaseMessage bizTalkMessage, IRequestChannel channel)
       at Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfClient`2.SendMessage(IBaseMessage bizTalkMessage)

    In the Application EventLog, I see all my "System.Diagnostics.EventLog.WriteEntry" - through "Pipeline5". So I know that my pipline code runs up to the return statement.

    So why is it failing?  What does the XmlReader do that messes things up?

    Neal Walters

    Tuesday, December 8, 2015 4:41 PM


All replies

  • It just occured I probably need to seek back to beginning of stream, about to try this:

    readOnlySeekableStream.Seek(0, SeekOrigin.Begin);


    Tuesday, December 8, 2015 5:50 PM
  • Sadly, still not working.

    Read this page:

    Changed my code to remove all .close() and .dispose() related to stream, and added this code at the bottom:

                readOnlySeekableStream.Seek(0, SeekOrigin.Begin);
                System.Diagnostics.EventLog.WriteEntry("LOGGER", "Pipeline6-ReSeek to 0");
                return pInMsg;

    The write to EventLog proves to me that I'm running and properly deploy the new version of my pipeline component, restarted hosts, etc... So I see "Pipeline6-Reseek" in the EventLog on my last run, and I'm still getting the error.  It makes sense that the above would fix the issue.  What else should I try?


    Tuesday, December 8, 2015 6:00 PM
  • Grasping at straws, I tried this and it worked:

                inboundStream.Seek(0, SeekOrigin.Begin);

    So I basically changed back to the original stream, instead of the derived stream.

    I just did a more organized blog on this subject here:


    Tuesday, December 8, 2015 6:05 PM
  • Hi Neal - have a read of this blog article of mine - might provide some further information for you:

    (Apologies - it's quite a long one!).

    I haven't had a chance to read your blog yet but will do so...

    In the implementation described in my post, I create my own streaming class and override the read method...  The read method is called repeatedly by the BizTalk endpoint manager (EPM - intermediary between the ports and the MessageBox) until there are no more bytes to be read.

    I think your issue is that you need to rewind your stream back to the beginning again in your execute method, so it's ready to be read by the EPM (which you have effectively done):

    pInMsg.BodyPart.Data.Position = 0;



    Wednesday, December 9, 2015 12:29 AM