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

    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", "http://schemas.microsoft.com/BizTalk/2003/system-properties", // context.Read("OutboundTransportLocation", "http://schemas.microsoft.com/BizTalk/2003/system-properties")); 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 = "http://MyUSSite.com/MyApp/MyService.svc"; break; case ("EM"): regionSpecificURL = "http://MyEMSite.com/MyApp/MyService.svc"; break; case ("AP"): regionSpecificURL = "http://MyAPSite.com/MyApp/MyService.svc"; break; default: regionSpecificURL = "http://MyINVALIDREGIONAPSite.com/MyApp/MyService.svc"; break; } System.Diagnostics.EventLog.WriteEntry("LOGGER", "Pipeline4 regionSpecificURL=" + regionSpecificURL); // Three parms: 1) context proeprty, 2) context string namespace 3) value context.Promote( "OutboundTransportLocation", "http://schemas.microsoft.com/BizTalk/2003/system-properties", regionSpecificURL); context.Promote( "IsDynamicSend", "http://schemas.microsoft.com/BizTalk/2003/system-properties", true);

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

    In this issue: https://social.msdn.microsoft.com/Forums/en-US/f86c5ab1-cd2e-4364-bf9f-4caac4f5f9ff/how-to-override-just-the-url-of-a-wcf-sendport-from-an-orchestration?forum=biztalkr2adapters&prof=required,

    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?

    Thanks,
    Neal Walters
    http://MyLifeIsMyMessage.net


    Tuesday, December 08, 2015 4:41 PM

Answers

All replies