我正在使用 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 中隐藏二进制文件的技术变得有意义了。所以也许我的测试本身引起了不同的问题。
但是,我希望能够以某种方式验证我的回答。我可以做些什么来分析从网站获得的响应,而不导致消息加载?上下文属性中没有什么有用的东西,所以我很好奇我能做什么。
最佳答案
我不太确定如何理解您的错误(特别是没有看到您实际用于检查消息的代码),但无论哪种方式,我认为您应该在自定义管道组件中执行此操作,对于几个原因。
- 如果您正在处理大型二进制对象,则将 XmlDocument 加载到编排中将会是令人望而却步的事情。
- 尝试对二进制数据使用 XPath 是行不通的
- 尝试在 HTML 上使用 XPath 并不总是有效
您可以非常轻松地检查管道组件中的消息大小(例如,pInMsg.BodyPart.GetOriginalDataStream().Length
)。您还可以尝试读取流的前几个字节,并更有效地检查这些字节是否符合某些条件。
关于stream - BizTalk:分析隐藏在 XmlDocument 中的二进制 blob?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33696919/