使用 LINQ to XML 解析 SOAP 消息
我正在加快 C# 中的 Linq to XML 的速度,并尝试解析以下消息,但似乎没有取得太大进展。这是肥皂消息,我不确定是否需要使用名称空间。这是我尝试格式化的 SOAP 消息。任何帮助将不胜感激。我正在尝试提取值。谢谢。
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Lookup xmlns="http://ASR-RT/">
<objIn>
<transactionHeaderData>
<intWebsiteId>1000</intWebsiteId>
<strVendorData>test</strVendorData>
<strVendorId>I07</strVendorId>
</transactionHeaderData>
<intCCN>17090769</intCCN>
<strSurveyResponseFlag>Y</strSurveyResponseFlag>
</objIn>
</CCNLookup>
</soap:Body>
</soap:Envelope>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果这是关于与 SOAP 服务交互,请使用
添加服务参考或wsdl.exe。
如果这只是解析 XML,假设您已将 SOAP 响应放入名为soapDocument 的 XDocument 中:
这将为您提供一个 匿名类型 您在该方法中将其作为完全强类型对象进行处理。
If this is about interacting with a SOAP service please use
Add Service Reference or wsdl.exe.
If this is just about parsing the XML, assuming you've got the SOAP response into an XDocument named soapDocument:
That will give you an IEnumerable of anonymous types you deal with as fully strongly typed objects within that method.
通过调用 XDocument.Load() 或类似方法,使用 Linq 的 XDocument 加载 XML 文本。然后,您可以使用以下函数遍历 xdoc 根的元素树
Use Linq's XDocument to load the XML text by calling
XDocument.Load()
or similar. Then you can walk through the tree of elements off the xdoc's Root, using functions like您可以将 XML 放入 XElement 中,然后只需执行以下操作:
或
rsp.Descendants("objIn").ToList();
我认为这是最好的方法。我认为 XElement 是最好的选择。
You can get your XML into an XElement an then just do:
Or
rsp.Descendants("objIn").ToList();
I think this is the best way to do it. I think that XElement is the best choice.