如何使用c#获取SOAP返回值

时间:2013-07-26 11:01:38

标签: c# soap

我有SOAP响应,如下所示

<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">
<SOAP-ENV:Header/><SOAP-ENV:Body>
<Login xmlns=\"http://s.com/sch">   
<error/>
<userid>11</userid>
</Login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我正在使用XDocument来解析此SOAP。我试图获得userid

的值

我的代码是

XDocument xDocc = XDocument.Parse(responseSOAP);
string uid = xDocc.Descendants("userid").First().Value;

我无法获得11的价值,它只返回NULL

2 个答案:

答案 0 :(得分:2)

这应该有效:

XDocument xDocc = XDocument.Parse(responseSOAP);
XmlReader xr = xDocc.CreateReader();
xr.ReadToFollowing("userid");
string uid = xr.ReadElementString();

答案 1 :(得分:1)

试试这个:

var result = from p in xDocc.Descendants() 
             where p.Name.LocalName == "userid" select p.Value;