2012-12-20 48 views
0

編輯ASP.NET MVC Web應用程序連接到WCF的Web服務的錯誤處理大量數據

我使用MVC 3試着撥打了MVC服務已經消耗WCF服務的方法,並得到以下錯誤當我調用該方法時。

格式化程序在嘗試反序列化消息時拋出異常:嘗試反序列化參數http://tempuri.org/:emailData時發生錯誤。 InnerException消息是'反序列化EmailPO類型的對象時發生錯誤。讀取XML數據時,超過了最大字符串內容長度限額(8192)。可以通過更改創建XML閱讀器時使用的XmlDictionaryReaderQuotas對象上的MaxStringContentLength屬性來增加此配額。 89行,1075位。'。有關更多詳細信息,請參閱InnerException。

這不像我想的那樣與ASP.NET有關。我有一個WPF應用程序,它也使用本地與卡西尼協同工作的服務。當我使用相同的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> 
,它工作

<?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-一切,其他線程

WPF應用程序有什麼錯誤實際上國家一起說,但我沒有看到,其中在該點8192連適用或可能指的是什麼。如果有人能指引我正確的方向,我會非常感激。如果需要的話,我的類,它指的是這個樣子的。隨着數據成員/ 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; } 


    } 

編輯 - UPDATE

<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"/> 

還嘗試給它一個名稱並更新端點以使用相同的名稱進行行爲配置

回答

0

這是一個問題,其中對象的序列化圖超過了默認的最大限制。 因此在Service config中添加這一行。

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

它適用於我在WCF服務配置。

編輯:您可以參考以下鏈接CLICK here

+0

這並沒有解決問題。請參閱上面的編輯 – gcoleman0828

相關問題