使用 C# 和 XDocument/XElement 解析 Soap 响应 [英] Using C# and XDocument/XElement to parse a Soap Response
本文介绍了使用 C# 和 XDocument/XElement 解析 Soap 响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是来自我的 SuperDuperService 的示例肥皂响应:
Here is a sample soap response from my SuperDuperService:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<MyResponse xmlns="http://mycrazyservice.com/SuperDuperService">
<Result>32347</Result>
</MyResponse>
</soap:Body>
</soap:Envelope>
出于某种原因,当我尝试获取结果"的后代或元素时,我得到了空值.它与命名空间有关吗?有人可以提供一个解决方案来从中检索结果吗?
For some reason when I try to grab the Descendant or Element of "Result" I get null. Does it have something to do with the Namespace? Can someone provide a solution to retrieve Result from this?
推荐答案
你可能想尝试这样的事情:
You might want to try something like this:
string myNamespace= "http://mycrazyservice.com/SuperDuperService";
var results = from result in yourXml.Descendants(XName.Get("MyResponse", myNamespace))
select result.Element("Result").value
这台笔记本电脑上没有 VS,所以我无法仔细检查我的代码,但它应该会为您指明使用 LINQ to SQL 的正确方向.
Don't have VS on this laptop so I can't double check my code, but it should point you in the right direction using LINQ to SQL.
这篇关于使用 C# 和 XDocument/XElement 解析 Soap 响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文