2011-12-02 53 views
2

我想使用WCF上傳文件。 16K以下的所有東西都可以正常工作,但任何情況都會拋出此錯誤:WCF MaxArrayLength更改設置不會保持

反序列化System.Byte []類型的對象時出現錯誤。讀取XML數據時,超出了最大數組長度限額(16384)。這種配額可能會增加通過更改XmlDictionaryReaderQuotas中的MaxArrayLength屬性創建XML閱讀器

這是我的WCF服務的app.config

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 

    <system.web> 
    <compilation debug="true" /> 
    </system.web> 
    <!-- When deploying the service library project, the content of the config file must be added to the host's 
    app.config file. System.Configuration does not support config files for libraries. --> 
    <system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="WSHttpBinding_IRAISAPI" closeTimeout="00:01:00" 
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
      maxBufferPoolSize="50000000" maxReceivedMessageSize="50000000" 
      messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" 
      allowCookies="false"> 
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="104857600" 
      maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      <reliableSession ordered="true" inactivityTimeout="00:10:00" 
      enabled="false" /> 
      <security mode="Message"> 
      <transport clientCredentialType="Windows" proxyCredentialType="None" 
       realm="" /> 
      <message clientCredentialType="Windows" negotiateServiceCredential="true" 
       algorithmSuite="Default" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <services> 
     <service name="RAIS_WCF_Services.RAISAPI"> 
     <endpoint address="" binding="wsHttpBinding" contract="RAIS_WCF_Services.IRAISAPI"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8732/Design_Time_Addresses/RAIS_WCF_Services/Service1/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="True"/> 
      <serviceDebug includeExceptionDetailInFaults="True" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 

</configuration> 

,在這裏當對象使用的是我的客戶的app.config

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" /> 
    </startup> 
    <system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="WSHttpBinding_IRAISAPI" closeTimeout="00:01:00" 
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
      maxBufferPoolSize="50000000" maxReceivedMessageSize="50000000" 
      messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" 
      allowCookies="false"> 
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="104857600" 
      maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      <reliableSession ordered="true" inactivityTimeout="00:10:00" 
      enabled="false" /> 
      <security mode="Message"> 
      <transport clientCredentialType="Windows" proxyCredentialType="None" 
       realm="" /> 
      <message clientCredentialType="Windows" negotiateServiceCredential="true" 
       algorithmSuite="Default" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:8732/Design_Time_Addresses/RAIS_WCF_Services/Service1/" 
     binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IRAISAPI" 
     contract="RAIS.IRAISAPI" name="WSHttpBinding_IRAISAPI"> 
     <identity> 
      <dns value="localhost" /> 
     </identity> 
     </endpoint> 
    </client> 
    </system.serviceModel> 
</configuration> 

任何幫助非常感謝!謝謝。

回答

1

它看起來不像你的服務沒有正確引用你的綁定配置。

在你的服務配置中搜索WSHttpBinding_IRAISAPI,你會明白我的意思。

您需要:

<endpoint address="" binding="wsHttpBinding" 
       contract="RAIS_WCF_Services.IRAISAPI" 
       bindingConfiguration="WSHttpBinding_IRAISAPI"> 
     <identity> 
     <dns value="localhost" /> 
     </identity> 
    </endpoint> 
+1

這是它...愚蠢的監督。非常感謝你的幫助! – Ryan

+0

當你手工做東西時,真的很容易錯過! :) –

0

我假設你的意思是在添加服務引用之後,客戶端配置中沒有自動設置maxArrayLength設置,並且/或者在更新客戶端的服務引用之後它正在丟失?如果這是你正在經歷的,這是設計。諸如超時,maxArrayLength等設置不在WSDL中公開,因此在服務引用被創建/更新時不能由服務推送到客戶端。

0

嘗試將此global config添加到您的服務器端配置中。這會將您的服務綁定綁定到綁定配置。

<system.serviceModel> 
    <protocolMapping> 
     <remove scheme="http"/> 
     <add scheme="http" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IRAISAPI" /> 
    </protocolMapping> 
</system.serviceModel> 

您還可以使用behaviors/serviceBehaviors/behavior/serviceMetadata/httpGetBindingConfiguration獲得更本地化的解決方案。

相關問題