如何在c#中读取soap响应?

如何在c#中读取soap响应?,c#,asp.net,C#,Asp.net,Soap响应为: <?xml version="1.0" encoding="utf-8" ?> <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:B

Soap响应为:

<?xml version="1.0" encoding="utf-8" ?> 
<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>
        <LoginResponse xmlns="http://example.com/SystemIntegration">
            <FirstName>@FirstName</FirstName>
            <LastName>@LastName</LastName>
        </LoginResponse>
    </soap:Body>
 </soap:Envelope>

@名字
@姓氏
我试图把它理解为:

XDocument doc = XDocument.Parse(strReturnStatus);
List<XElement> result = doc.Elements("LoginResponse").ToList();
for (int intc = 0; intc <= result.Count - 1; intc++)
{
    strResponseCode = result[intc].Element("FirstName").Value.ToString();
    strResponseText = result[intc].Element("LastName").Value.ToString();
}
XDocument doc=XDocument.Parse(strReturnStatus);
列表结果=doc.Elements(“LoginResponse”).ToList();

对于(intc=0;intc来说,最简单的事情是为您的服务创建一个代理类

您可以使用o。输入服务的URL,VisualStudio将为您生成源代码

从那时起,您可以使用C#代码访问服务,无需手动提取SOAP消息的有效负载


注意:如果您是该服务的实现者:ASMX webservices已经被弃用很长时间了。如果可以,请使用WCF。

使用XDocumentobject中的后代()方法浏览XML节点以获取元素,您可以按照本文提供的步骤操作。

这是名称空间规范的问题。请参阅以下答案: