請原諒,我是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