2010-05-04 29 views
9

我有一個使用wsHttpBinding的WCF服務。服務器配置如下:WCF - 讀取XML數據時已超出最大可命名字符計數配額(16384)

<bindings> 
     <wsHttpBinding> 
     <binding name="wsHttpBinding" maxBufferPoolSize="2147483647" 
      maxReceivedMessageSize="2147483647"> 
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
      maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
      <security mode="None"> 
      <transport clientCredentialType="Windows" proxyCredentialType="None" 
       realm="" /> 
      <message clientCredentialType="Windows" negotiateServiceCredential="true" 
       algorithmSuite="Default" establishSecurityContext="true" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 

在客戶端,我包括WCF的服務的服務參考。如果我在我的IService中有90個操作契約,但是如果再添加一個OperationContract比我無法更新服務引用,並且我能夠添加該服務引用,那麼它會很好用。在this文章中提到,通過更改這些配置文件(即devenv.exe.config,WcfTestClient.exe.config和SvcUtil.exe.config)它可以工作,但即使在那些配置文件中包含那些綁定,仍然會彈出錯誤消息

下載「http://10.0.3.112/MyService/Service1.svc/mex」時出錯。 請求失敗,HTTP狀態400:錯誤的請求。 元數據包含無法解析的引用:'http://10.0.3.112/MyService/Service1.svc/mex'。 XML文檔中存在錯誤(1,89549)。 讀取XML數據時,超過了最大的可命名字符計數配額(16384)。名稱表是用於存儲XML處理期間遇到的字符串的數據結構 - 具有非重複元素名稱,屬性名稱和屬性值的長XML文檔可能會觸發此配額。可以通過更改創建XML閱讀器時使用的XmlDictionaryReaderQuotas對象上的MaxNameTableCharCount屬性來增加此配額。第1行,位置89549. 如果服務在當前解決方案中定義,請嘗試構建解決方案並再次添加服務參考。

任何想法如何解決這個?

回答

11

嘗試以下操作:

在Visual Studio中,其中的devenv.exe所在的安裝目錄(如C:\ Program Files文件\微軟的Visual Studio 9.0 \ Common7 \ IDE)中添加本節進行到devenv的。 exe.cofig

<system.serviceModel> 
<client> 
    <endpoint binding="customBinding" bindingConfiguration="largeServiceBinding" contract="IMetadataExchange" name="http" /> 
</client> 

<bindings> 
    <customBinding> 
    <!-- NOTE: The binding name must be the same as specified in the config file of the wcf service --> 
    <binding name="largeServiceBinding" > 
     <textMessageEncoding> 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     </textMessageEncoding> 

     <httpTransport transferMode="Buffered" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/> 
    </binding> 

    </customBinding> 
</bindings> 
</system.serviceModel> 

在您的WCF服務的app.config中添加相同的綁定:

<bindings> 
    <customBinding > 
    <!-- NOTE: The binding name must be the same as specified in the devenv.exe.config file located ..\Common7\IDE folder of the VS installation directory --> 
    <binding name="largeServiceBinding" > 
     <textMessageEncoding> 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
      maxNameTableCharCount="2147483647" /> 
     </textMessageEncoding> 
     <httpTransport transferMode="Buffered" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/> 
    </binding> 
    </customBinding> 
</bindings> 

請注意,來自兩個文件的綁定標記的名稱屬性必須匹配(例如, largeServiceBinding)

最後添加以下MEX端點到您的服務標籤:

<endpoint address="mex" binding="customBinding" contract="IMetadataExchange" bindingName="testBinding" bindingConfiguration="largeServiceBinding" name="http"/> 

這可能是這樣的:

<services> 
    <service behaviorConfiguration="MyServiceBehavior" 
    name="MyService.MyService"> 
    <endpoint address="" binding="wsHttpBinding" contract="MyService.IMyService"> 
     <identity> 
     <dns value="localhost" /> 
     </identity> 
    </endpoint> 
    <endpoint address="mex" binding="customBinding" contract="IMetadataExchange" bindingName="testBinding" bindingConfiguration="largeServiceBinding" name="http"/> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost:8731/Design_Time_Addresses/MyService/MyService/" /> 
     </baseAddresses> 
    </host> 
    </service> 
</services> 
+0

感謝您的答覆將嘗試並讓您知道結果。 – Jankhana 2010-05-05 04:56:44

+0

它工作了,謝謝。在它工作之後,我必須在客戶端中更改服務端點設置。謝謝!!!! – Jankhana 2010-05-05 05:51:53

+0

這也適用於我,但沒有必要添加一個新的綁定,我剛剛更新'readerQuotas'與上述。 – endyourif 2012-10-11 20:39:43

1

有一點要承認的是,消息指SvcUtil工具讀者配額不是服務的! Svcutil對它可以讀取多少元數據有限制。這個限制可以通過配置文件來改變。解決方案是爲svcutil創建一個配置文件,並將它放在與該工具相同的文件夾中。下一次運行svcutil時,配置文件的值將被考慮在內。

http://geekswithblogs.net/claraoscura/archive/2007/08/20/114806.aspx

1

在你的app.config或DLL。在客戶端添加配置:

<configuration> 
<system.serviceModel> 
<bindings> 
<netTcpBinding> 
<binding name="myMex" maxReceivedMessageSize="1024000"> <!-- modify this to avoid stupid error --> 
<readerQuotas maxNameTableCharCount="163840" /> <!-- DO NOT touch this one --> 
<security mode="None" /> 
</binding> 
</netTcpBinding> 
</bindings> 

... 

<client> 
<endpoint binding="netTcpBinding" bindingConfiguration="myMex" 
contract="IMetadataExchange" name="net.tcp" /> 

... 

     </client> 
    </system.serviceModel> 
</configuration> 

然後你去! 這是WCF真正令人討厭的事情之一,通常谷歌只會讓你很多bs。浪費噸這個時間。

4

我知道它已經有一段時間,但我得到了同樣的問題,發現其他(簡單的)解決方案in codeproject

在給那裏的值在代碼而不是config文件設置的解決方案。

 BasicHttpBinding binding = new BasicHttpBinding(); 
     binding.Security.Mode = BasicHttpSecurityMode.Transport; 
     binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; 
     binding.MaxReceivedMessageSize = 50000000; 
     binding.ReaderQuotas.MaxArrayLength = 50000000; 
     binding.ReaderQuotas.MaxStringContentLength = 50000000; 
     binding.ReaderQuotas.MaxNameTableCharCount = 50000000; 
     EndpointAddress endpoint = new EndpointAddress(new Uri("https://server/EWS/Exchange.asmx")); 
     ExchangeServicePortTypeClient ews = new ExchangeServicePortTypeClient(binding, endpoint); 

然而,我在config文件相關的值更改的值(在<binding><readerQuotas>部分兩者)並解決了這個問題(而不是添加自定義綁定):

   <binding name="ITransactionProcessor" closeTimeout="00:01:00" 
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
        maxBufferSize="50000000" maxBufferPoolSize="524288" maxReceivedMessageSize="50000000" 
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
        useDefaultWebProxy="true"> 
        <readerQuotas maxDepth="32" maxStringContentLength="50000000" maxArrayLength="50000000" 
         maxBytesPerRead="4096" maxNameTableCharCount="50000000" /> 
        <security mode="TransportWithMessageCredential"> 
         <transport clientCredentialType="None" proxyCredentialType="None" 
          realm="" /> 
         <message clientCredentialType="UserName" algorithmSuite="Default" /> 
        </security> 
       </binding> 

我希望這會幫助某人:)

相關問題