Подтвердить что ты не робот

WCF: максимальная квота длины массива (16384) была превышена при чтении данных XML

Я знаю, что это было задано довольно много раз, и поверьте мне, что я смотрел и пытался много из них на полдня, но все равно не могу пройти мимо этого.

Я пытаюсь представить содержимое какой-либо формы (которая также может включать вложение) через веб-службу, но продолжайте получать следующую ошибку, когда я пытаюсь подключить что-либо, кроме крошечного файла.

Моя полная ошибка:

Формататор сделал исключение, пытаясь десериализовать сообщение: произошла ошибка при попытке десериализации параметра http://tempuri.org/:scChildForm. Сообщение InnerException было "Там была ошибка десериализации объекта типа MashForms.Models.SCChildrenForm. Максимальная длина длины массива (16384) был превышен при чтении XML-данных. Эта квота может быть увеличено путем изменения свойства MaxArrayLength на Объект XmlDictionaryReaderQuotas, используемый при создании XML-ридера. Строка 1, позиция 41713. '. Дополнительную информацию см. В InnerException.

Независимо от того, насколько я пытаюсь переопределить это значение в web.config службы WCF и веб-клиента, он все равно сообщает об этом как о максимальных, так и последующих ошибках.

WCF Web.Config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
        <!--<httpRuntime maxRequestLength="409600" executionTimeout="300" />-->
  </system.web>
  <connectionStrings>
    <add name="MashFormsContext" connectionString="Data Source=ServerName;Initial Catalog=MashFormsDev;Persist Security Info=True;User ID=UserName;Password=Password" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
                    <dataContractSerializer maxItemsInObjectGraph="2147483647" />
                    <serviceTimeouts transactionTimeout="05:05:00" />
                    <serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" maxConcurrentInstances="2147483647" />
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!--<serviceMetadata httpsGetEnabled="true"/>-->
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />
          <!--<StructureMapServiceBehavior />-->
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="false" />
    <extensions>
      <behaviorExtensions>
      </behaviorExtensions>
    </extensions>

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

    </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
        <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Мой веб-клиент Web.Config

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-PublicForms-20121112151426;Integrated Security=SSPI" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="2880" />
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>

    <sessionState mode="InProc" customProvider="DefaultSessionProvider">
      <providers>
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
      </providers>
    </sessionState>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Data" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
  <system.serviceModel>

    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IInsertNewForm" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
            maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:54070/MashPortalService/InsertNewForm.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IInsertNewForm"
        contract="InsertNewForm.IInsertNewForm" name="BasicHttpBinding_IInsertNewForm" />
    </client>
  </system.serviceModel>
</configuration>

Моя служба WCF будет принимать очень маленькие файлы, но не больше, даже не 28k.

В качестве дополнительной заметки, когда я первоначально добавляю ссылку на службу в WebClient, она не по умолчанию не имеет больших значений, она создает ее следующим образом:

Веб-клиент по умолчанию Web.config

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IInsertNewForm" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:54070/MashPortalService/InsertNewForm.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IInsertNewForm"
        contract="InsertNewForm.IInsertNewForm" name="BasicHttpBinding_IInsertNewForm" />
    </client>
  </system.serviceModel>

Обновление 1: Ответ на Eugene

using System.ServiceModel;
using MashForms.Models;

namespace MashPortalService
{
    [ServiceContract]
    public interface IInsertNewForm
    {
        //Testing operations
        [OperationContract]
        string TestReturnInput(string s);
        [OperationContract]
        bool Ping();

        //Child
        [OperationContract]
        int InsertFormChildGettingIdBack(SCChildrenForm scChildForm);
    }
}

Обновление 2: добавлена ​​конечная точка обслуживания, предложенная

</bindings>
        <services>
            <service name="MashPortalService">
                <endpoint address="http://localhost:54070/MashPortalService/InsertNewForm.svc" binding="basicHttpBinding"
                                    bindingConfiguration="BasicHttpBinding_IInsertNewForm" contract="InsertNewForm.IInsertNewForm" />
            </service>
        </services>

Но все же у меня такая же ошибка.

4b9b3361

Ответ 1

Спасибо за все предложения. К сожалению, ни одно из предложений не устранило проблему, но все же казалось, что она извлекает значение из где-то, что перегружает его.

Мне удалось получить работу с большими файлами, спустив маршрут customBinding.

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="MashPortalService.MyServiceBehaviour">
                <dataContractSerializer maxItemsInObjectGraph="2147483647"  />
                <serviceTimeouts transactionTimeout="05:05:00" />
                <serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" maxConcurrentInstances="2147483647" />
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true"/>
                <!--<serviceMetadata httpsGetEnabled="true"/>-->
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="true" />
                <!--<StructureMapServiceBehavior />-->
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="false" />
    <extensions>
        <behaviorExtensions>
        </behaviorExtensions>
    </extensions>
    <bindings>
        <customBinding>
            <binding name="MashCustomBinding"
                    closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00">
                <textMessageEncoding messageVersion="Soap11" maxReadPoolSize="2147483647" maxWritePoolSize="2147483647">
                    <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
                </textMessageEncoding>
                <httpTransport transferMode="Streamed" maxReceivedMessageSize="2147483647"/>
            </binding>
        </customBinding>
    </bindings>
    <services>
        <service behaviorConfiguration="MashPortalService.MyServiceBehaviour" name="MashPortalService.InsertNewForm">
            <endpoint address="" binding="customBinding"
                                bindingConfiguration="MashCustomBinding" contract="MashPortalService.IInsertNewForm" />
        </service>
    </services>
</system.serviceModel>

Ответ 2

Это только гость, использующий wsHttpBinding. Вы можете написать ниже код в web.config

<wsHttpBinding>
      <binding name="MyBinding" maxReceivedMessageSize="2147483647" />
</wsHttpBinding>

Ответ 3

Вы определили привязку "BasicHttpBinding_IInsertNewForm", но действительно ли вы подключаете эту привязку к своей службе? Вы делаете это в коде? Если да, отправьте код. Потому что я не вижу его в вашей конфигурации... Обычно у вас есть <services> внутри системы < system.servicemodel > где привязка фактически подключена к вашей службе.