簡體   English   中英

WCF DefaultBinding 未用於新的 WsHttpBinding

[英]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;

您是否嘗試過此鏈接https://social.msdn.microsoft.com/Forums/vstudio/en-US/17592561-c470-452a-a52c-2a5a2839582c/metadataexchangeclient-and-nametable-character-count-quota?forum=wcf

這是我們代碼中的一個錯誤(HTTP-GET 會忽略您傳遞的綁定)。 有幾種解決方法

你能看看他們中的任何一個對你有用嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM