我正在嘗試訪問此 SOAP 回應中的所有元素,但我發現很難訪問回應中的元素。我正在嘗試使用 XmlNamespaceManager,但不知道該怎么做。請問誰能給我一個見解?
以下是回復;
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header/>
<soap:Body>
<Result>
<statuscode>200</statuscode>
<Customer>10001252</Customer>
<CustomerName>MBOKO FARMS</CustomerName>
<CustomerFullName>MBOKO FARMS/0 ANAMBRA</CustomerFullName>
<FiscalAddress/>
<VATRegistration/>
</Result>
</soap:Body>
</soap:Envelope>
并且;
我嘗試使用 XmlNamespaceManager,但形成 addnamsespace 讓我很艱難。我想從這個回應中訪問不同的元素。標簽名
uj5u.com熱心網友回復:
如果您只需要閱讀該訊息,那么簡單的解決方案就是復制整個訊息。在 Visual Studio 中新建一個 cs 檔案,并清除它。然后編輯-> 選擇性粘貼-> 將 Xml 粘貼為類。
然后
using System.Xml.Serialization;
internal class Program
{
static void Main(string[] args)
{
Envelope envelope = Read(@"C:\temp\soap_xml.xml");
var name = envelope.Body.Result.CustomerFullName;
}
private static Envelope Read(string file)
{
XmlSerializer serializer = new XmlSerializer(typeof(Envelope));
using (StreamReader reader = new StreamReader(file))
{
return (Envelope)serializer.Deserialize(reader)!;
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/531952.html
標籤:C#。网asp.net-mvc-3xml 解析肥皂客户端
上一篇:風控決策引擎——決策流路徑規劃
