请原谅,我是SOAP和C#的新手。我似乎无法弄清楚如何正确设置命名空间以在SOAP响应中查找节点。解析C#中的SOAP响应......不理解XML命名空间
这里的响应,如果网络服务查询返回空:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:VXWSResponse xmlns:ns="vx.sx">
<ns:List ns:id="result" />
</ns:VXWSResponse>
</soapenv:Body>
</soapenv:Envelope>
这里的响应,如果返回的数据:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:VXWSResponse xmlns:ns="vx.sx">
<ns:List ns:id="result">
<ns:Badge>USER DATA</ns:Badge>
</ns:List>
</ns:VXWSResponse>
</soapenv:Body>
</soapenv:Envelope>
我只需要知道,如果该标签存在。
这是我到目前为止。
XmlNamespaceManager manager = new XmlNamespaceManager(xml.NameTable);
manager.AddNamespace("ns", "vx.sx");
manager.AddNamespace("id", "result");
xmlNode badge = xml.SelectSingleNode("//id:Badge", manager);
XmlNode result = xml.SelectSingleNode("//ns:result", manager);
两个节点都返回null。我已经查看了很多其他文章,但我没有看到如何正确地在响应XML中寻址名称空间。
任何帮助表示赞赏!
你真的需要手动解析SOAP吗?你想达到什么目的? – Dusan 2013-05-02 20:28:54
我无法控制Web服务,因此需要在CE 5/.NET 2上运行,所以我不确定是否可以使用服务引用。我只需要测试标签是否存在。 –
alexsd
2013-05-02 20:31:53