[英]How to read the WSDL of a WCF service from a URL in C#
我正在嘗試從URL讀取WSDL,以動態生成WCF服務的代理。 這是我的代碼:
XmlTextReader xmlTextReader = new XmlTextReader(new StringReader(description))
if (ServiceDescription.CanRead(xmlTextReader))
{
...
}
我從方法ServiceDescription.CanRead
獲得XmlException
。
錯誤消息為“ 根級別的數據無效。第1行,位置1 ”。
瀏覽IE中的WDSL URL,我可以在標簽<wsdl:definitions ...> ... </wsdl:definitions>
之前的開頭看到以下標簽,該標簽沒有出現在chrome中。
<?xml version="1.0" encoding="UTF-8"?>
這可能是問題嗎? 但我認為ServiceDescription.CanRead
應該能夠識別出來。 任何提示將不勝感激。
嘗試在問題中包含的第一行之前添加以下內容:
var byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
if (description.StartsWith(byteOrderMarkUtf8))
{
var lastIndexOfUtf8 = byteOrderMarkUtf8.Length - 1;
description = description.Remove(0, lastIndexOfUtf8);
}
從這里借來的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.