![](/img/trans.png)
[英]WSHttpBinding in WCF port 8080 is being used by another application
[英]WCF DefaultBinding not used on new WsHttpBinding
我有一個在特定端點連接到 web 服務的 3rd 方庫。 對於某些服務,我收到以下異常:
Message=The maximum nametable character count quota (16384) has been exceeded while reading XML data. The nametable is a data structure used to store strings encountered during XML processing - long XML documents with non-repeating element names, attribute names and attribute values may trigger this quota. This quota may be increased by changing the MaxNameTableCharCount property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 1339.
解決辦法是,增加ReaderQuoata。 WCF 通過配置文件建議這一點。
我的 app.config 現在看起來像:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding>
<readerQuotas maxNameTableCharCount="2147483647" />
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
當我現在創建一個新的 WsHttpBinding 時,它的值仍然是默認值 16384。
class Program
{
static void Main(string[] args)
{
WSHttpBinding x = new WSHttpBinding();
Console.WriteLine(x.ReaderQuotas.MaxNameTableCharCount); //prints 16384
}
}
我錯過了什么?
WSHttpBinding x = new WSHttpBinding();
使用框架默認值創建WSHttpBinding
的新實例。 即使您在配置文件中定義了默認綁定配置,您的代碼也沒有使用它(有關源代碼,請參閱WSHttpBinding.cs )。 換句話說,調用WSHttpBinding
的無參數構造函數不會應用任何關聯配置文件中的默認綁定,至少我可以看到。
你有幾個選擇。 首先,在您的配置文件中為綁定配置命名並引用它。 其次,在以編程方式創建綁定時將值分配給XmlDictionaryReaderQuotas
。
選項1
<bindings>
<wsHttpBinding>
<binding name="MyBinding">
<readerQuotas maxNameTableCharCount="2147483647" />
</binding>
</wsHttpBinding>
</bindings>
WSHttpBinding x = new WSHttpBinding("MyBinding");
選項 2
WSHttpBinding x = new WSHttpBinding();
x.ReaderQuotas rq = new XmlDictionaryReaderQuotas();
rq.MaxNameTableCharCount = Int32.MaxValue;
這是我們代碼中的一個錯誤(HTTP-GET 會忽略您傳遞的綁定)。 有幾種解決方法
你能看看他們中的任何一個對你有用嗎?
- 該服務是 WCF 服務嗎? 如果是這樣,您能否在該服務上啟用 mex 端點? 綁定將用於 mex 端點。 能
- 您使用發現協議( http://msdn2.microsoft.com/en-us/library/system.web.services.discovery.discoveryclientprotocol.aspx )從您的服務中獲取元數據? 這里使用的 XML 閱讀器
班級沒有任何配額。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.