0

编辑

我正在使用 MVC 3 尝试调用 MVC 服务已使用的 WCF 服务中的方法,并在调用该方法时收到以下错误。

格式化程序在尝试反序列化消息时抛出异常:尝试反序列化参数http://tempuri.org/:emailData时出错。InnerException 消息是“反序列化 EmailPO 类型的对象时出错。读取 XML 数据时已超出最大字符串内容长度配额 (8192)。可以通过更改创建 XML 阅读器时使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLength 属性来增加此配额。第 89 行,位置 1075。'。有关更多详细信息,请参阅 InnerException。

正如我所想,这不仅仅与 ASP.NET 有关。我有一个 WPF 应用程序,它也使用在本地与 Cassini 一起使用的此服务。当我使用相同的 WPF 应用程序并在发布相同的 WCF 服务后使用该服务时,运行相同的方法时也会出现上述错误。

ASP.NET MVC 客户端 Web.config 不起作用:

    <configSections>    
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
          <section name="UserInterface.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
      </configSections>
      <!--<location path="~/Content/images" allowOverride="false">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>      
        </system.web>
      </location>-->
      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="BasicHttpBinding_Configuration" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
                     allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="1073741824" maxBufferPoolSize="1073741824" 
                     maxReceivedMessageSize="1073741824" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
              <readerQuotas maxDepth="32" maxStringContentLength="65536" maxArrayLength="102400" 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://server1/WebServices/MasterEngine/MasterEngineService.svc?wsdl" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Configuration" contract="MasterEngineFarEnd.IMasterEngineService" name="BasicHttpBinding_IMasterEngineService" />
         --- Later on after company specific stuff --
<system.web>    
    <httpRuntime requestValidationMode="2.0" maxRequestLength="5120" executionTimeout="1200" />    
    <customErrors mode="Off" />
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />        
      </assemblies>
    </compilation>
    <authentication mode="Windows"></authentication>
    <membership>
      <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>
    <profile>
      <providers>
        <clear />
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
      </providers>
    </profile>
    <roleManager enabled="false">
      <providers>
        <clear />
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>
    <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.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>        
  </system.web>
  <system.webServer>
    <!--<httpErrors errorMode="Custom" existingResponse="Replace">
      <remove statusCode="404" subStatusCode="-1" />
      <remove statusCode="500" subStatusCode="-1" />
      <error statusCode="404" path="/Error/NotFound" responseMode="ExecuteURL" />
      <error statusCode="500" path="/Error/Error" responseMode="ExecuteURL" />
    </httpErrors>-->
    <validation validateIntegratedModeConfiguration="false" />
      <modules runAllManagedModulesForAllRequests="true"></modules>
    <handlers>
      <remove name="UrlRoutingHandler"/>
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Routing" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime> 

WCF 服务 (MasterEngine) Web.config

<system.serviceModel>
    <bindings>
      <basicHttpBinding>

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

        <!-- OLD CONFIG 
        <binding name="BasicHttpBinding_Configuration" 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://server2/WebServices/InternalService/InternalService.svc"
             binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Configuration"
             contract="InternalFarEnd.IInternalService" name="BasicHttpBinding_IInternalHubService" />

    </client>
  </system.serviceModel>


  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="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="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

不工作的 WPF 应用程序

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

      <diagnostics>
        <endToEndTracing propagateActivity="true" activityTracing="true"
          messageFlowTracing="true" />
      </diagnostics>
      <behaviors>
        <endpointBehaviors>
          <behavior>
            <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          </behavior>
        </endpointBehaviors>
        <serviceBehaviors>
          <behavior>
            <dataContractSerializer maxItemsInObjectGraph="2147483647" />
            <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
            <serviceMetadata httpGetEnabled="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"/>
          </behavior>
        </serviceBehaviors>
      </behaviors>

        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_Configuration" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" maxBufferPoolSize="1073741824"
                    maxReceivedMessageSize="1073741824" useDefaultWebProxy="true">
                    <readerQuotas maxDepth="1073741824" maxStringContentLength="1073741824"
                        maxArrayLength="1073741824" maxBytesPerRead="1073741824" maxNameTableCharCount="1073741824" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://server01-dev/WebServices/MasterEngine/MasterEngineService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Configuration"
                contract="MasterEngineFarEnd.IMasterEngineService" name="BasicHttpBinding_IMasterEngineService" />
        </client>
    </system.serviceModel>
</configuration>

可以工作的 WPF 应用程序

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

      <diagnostics>
        <endToEndTracing propagateActivity="true" activityTracing="true"
          messageFlowTracing="true" />
      </diagnostics>
      <behaviors>
        <endpointBehaviors>
          <behavior>
            <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          </behavior>
        </endpointBehaviors>
        <serviceBehaviors>
          <behavior>
            <dataContractSerializer maxItemsInObjectGraph="2147483647" />
            <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
            <serviceMetadata httpGetEnabled="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"/>
          </behavior>
        </serviceBehaviors>
      </behaviors>

        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_Configuration" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" maxBufferPoolSize="1073741824"
                    maxReceivedMessageSize="1073741824" useDefaultWebProxy="true">
                    <readerQuotas maxDepth="1073741824" maxStringContentLength="1073741824"
                        maxArrayLength="1073741824" maxBytesPerRead="1073741824" maxNameTableCharCount="1073741824" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://server01-dev/WebServices/MasterEngine/MasterEngineService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Configuration"
                contract="MasterEngineFarEnd.IMasterEngineService" name="BasicHttpBinding_IMasterEngineService" />
        </client>
    </system.serviceModel>
</configuration>

正如其他线程所说的那样,我已经添加了 max-everything 以及错误的实际状态,但是我看不到此时 8192 甚至适用于什么地方或它可能指的是什么。如果有人能指出我正确的方向,我将不胜感激。如果需要,它所指的我的类看起来像这样.. 设置了 DataMembers / DataContracts

电子邮件 PO 类

[DataContract]
    public class EmailPO
    {
        [DataMember]
        public string FromEmail { get; set; }

        [DataMember]
        public List<String> ToEmail { get; set; }

        [DataMember]
        public List<String> CcEmail { get; set; }

        [DataMember]
        public string FullHTML { get; set; }

        [DataMember]
        public string Subject { get; set; }

        [DataMember]
        public List<EmailClassLibrary.AttachmentItem> Attachments { get; set; }

        [DataMember]
        public string TableHeader { get; set; }


    }

编辑 - 更新

<system.serviceModel>

    <behaviors>
    <endpointBehaviors>
      <behavior>
        <dataContractSerializer maxItemsInObjectGraph="2147483647" />
      </behavior>
    </endpointBehaviors>
    </behaviors>


<endpoint address="http://server1/WebServices/MasterEngine/MasterEngineService.svc?wsdl"
                binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_Configuration"
                contract="MasterEngineFarEnd.IMasterEngineService"
                name="BasicHttpBinding_IMasterEngineService"/>

还尝试给它一个名称并更新端点以使用相同的名称进行 behaviorConfiguration

4

1 回答 1

0

这是我们对象的序列化图超出默认最大限制的问题。所以在服务配置中添加这一行。

  <system.serviceModel>
   ...
  <behaviors>
      <endpointBehaviors>
        <behavior name="Behaviors.EndpointBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    ...
  </system.serviceModel>

它在 WCF 服务配置中对我有用。

编辑:你可以参考这个链接点击这里

于 2012-12-20T05:56:16.320 回答