Вопрос

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

Была ошибка, десериализующая объект типа System.byte []. Квота максимальной длины массива (16384) была превышена при чтении данных XML. Эта квота может быть увеличена путем изменения свойства MaxarrayLength на объекте XmldictionaryReaderQuotas, используемом при создании XML Reader

Это мое приложение для службы WCF.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>

и вот мое клиентское приложение.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>

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

Это было полезно?

Решение

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

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

Тебе нужно:

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

Другие советы

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

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

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

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top