WCF MaxArrayLength Изменение настроек не останется - PullRequest
2 голосов
/ 03 декабря 2011

Я пытаюсь загрузить файлы с помощью WCF. Все под 16K работает нормально, но что-нибудь сверх выдает эту ошибку:

Произошла ошибка десериализации объекта типа System.Byte []. Максимальная квота длины массива (16384) была превышена при чтении данных XML. Эту квоту можно увеличить, изменив свойство MaxArrayLength объекта XmlDictionaryReaderQuotas, используемого при создании средства чтения 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>

Любая помощь очень ценится! Спасибо.

Ответы [ 3 ]

1 голос
/ 03 декабря 2011

Не похоже, что ваша служба неправильно ссылается на вашу конфигурацию привязки.

Найдите в своей конфигурации службы WSHttpBinding_IRAISAPI, и вы поймете, что я имею в виду.

Вам нужно:

    <endpoint address="" binding="wsHttpBinding" 
              contract="RAIS_WCF_Services.IRAISAPI"  
              bindingConfiguration="WSHttpBinding_IRAISAPI">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
0 голосов
/ 03 декабря 2011

Попробуйте добавить эту глобальную конфигурацию в конфигурацию на стороне сервера. Это свяжет привязку вашей службы к конфигурации привязки.

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

Вы также можете использовать behaviors/serviceBehaviors/behavior/serviceMetadata/httpGetBindingConfiguration для более локализованного решения.

0 голосов
/ 03 декабря 2011

Я предполагаю, что вы имеете в виду, что параметр maxArrayLength не устанавливается автоматически в конфигурации вашего клиента после добавления ссылки на службу и / или теряется после обновления ссылки на службу вашего клиента? Если это то, что вы испытываете, это по замыслу. Такие параметры, как тайм-ауты, maxArrayLength и т. Д., Не отображаются в WSDL и поэтому не могут быть переданы клиенту службой при создании / обновлении ссылки на службу.

...