我有这个SOAP响应,但我的代码没有读取GetLatestReadingByMeterNoResult子项。“手动”解析SOAP响应
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<GetLatestReadingByMeterNoResponse xmlns="http://www.multispeak.org/Version_3.0">
<GetLatestReadingByMeterNoResult objectID="112199498" utility="xxxxx">
<meterNo>112199498</meterNo>
<deviceID>112199498</deviceID>
<readingDate>2013-02-27T17:00:00.000Z</readingDate>
<posKWh>8406</posKWh>
<kW>15.508</kW>
<kWDateTime>2013-02-27T17:00:00.000Z</kWDateTime>
</GetLatestReadingByMeterNoResult>
</GetLatestReadingByMeterNoResponse>
</soapenv:Body>
</soapenv:Envelope>
代码:
XmlDocument resultXml = new XmlDocument();
XmlNamespaceManager mgr = new XmlNamespaceManager(resultXml.NameTable);
mgr.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
mgr.AddNamespace("", "http://www.multispeak.org/Version_3.0");
resultXml.LoadXml(soapResult);
XmlNodeList nodeList = resultXml.SelectNodes("//GetLatestReadingByMeterNoResult", mgr);
节点列表返回没有节点
您是否验证过您的预期响应是从服务器返回的?你可以通过像SoapUI这样的程序来做到这一点。 – TomJ 2013-02-27 19:43:50
肥皂响应是从流中返回的原始字符串。 – Fonzy 2013-02-27 19:47:20
你为什么不简单使用“添加服务参考”?有没有直接操纵XML直接用于SOAP的理由。 – 2013-02-27 19:51:17