我正在使用BizTalk 2013 R1通过http从网站下载二进制blob。当我收到blob时,我只是将消息存储在XmlDocument中。但是,有时该站点会返回我想要的文件,有时它会以包含错误信息的http页面的形式返回错误。
我试图通过尝试在我的返回消息上运行xpath来筛选它。特别是,我正在寻找/ html / head / title中出现的“Error”。我的想法是,如果它找到该文本,或者它根本解析为Xml,我就会出错,我应该抛出异常。
在实践中,当我尝试运行该xpath时,我得到了这个:
System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 128.30.52.100:80
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.OpenAndPush(Uri uri)
at System.Xml.XmlTextReaderImpl.PushExternalEntityOrSubset(String publicId, String systemId, Uri baseUri, String entityName)
at System.Xml.XmlTextReaderImpl.DtdParserProxy_PushExternalSubset(String systemId, String publicId)
at System.Xml.DtdParser.ParseExternalSubset()
at System.Xml.DtdParser.Parse(Boolean saveInternalSubset)
at System.Xml.DtdParser.System.Xml.IDtdParser.ParseInternalDtd(IDtdParserAdapter adapter, Boolean saveInternalSubset)
at System.Xml.XmlTextReaderImpl.ParseDtd()
at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.Load(TextReader txtReader)
at Microsoft.XLANGs.Core.Value.GetXmlDocument()
at Microsoft.XLANGs.Core.Value.RetrieveAs(Type t)
at Microsoft.XLANGs.Core.Part.get_XmlDocument()
at Microsoft.XLANGs.Core.Part.XPathLoad(Part sourcePart, String xpath, Type dstType)
at QTC.BizTalk.LSPDispatchIMNL.SendCommercialInvoice.segment3(StopConditions stopOn)
at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s, StopConditions stopCond, Exception& exp)
看到这个,它是有道理的,因为我相信BizTalk在后台处理消息作为流。突然间,在XmlDocuments中隐藏二进制的技术是有道理的。所以也许我的测试本身会导致一个不同的问题。
但我希望能够以某种方式验证我的回复。我可以做些什么来分析我从网站获得的响应,而不会导致加载消息?在上下文属性中没有任何有用的东西,所以我很好奇我能做什么。
答案 0 :(得分:2)
我不确定如何理解你的错误(特别是没有看到你实际用来检查消息的代码),但无论哪种方式,我认为你应该在自定义管道组件中执行此操作,几个原因。
您可以非常轻松地检查管道组件中的邮件大小(例如pInMsg.BodyPart.GetOriginalDataStream().Length
)。您还可以尝试读取流的前几个字节,并更有效地检查某些条件。