使用C#和XDocument/XElement解析Soap响应 [英] Using C# and XDocument/XElement to parse a Soap Response

查看:69
本文介绍了使用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>

由于某种原因,当我尝试获取结果"的后代或元素时,我得到了null.它与命名空间有关吗?有人可以提供从中检索结果的解决方案吗?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆