WCF maxReceivedMessageSize问题

WCF maxReceivedMessageSize问题,wcf,maxreceivedmessagesize,Wcf,Maxreceivedmessagesize,我的常见错误是MaxReceivedMessageSize为65536 在阅读了论坛上的一些相关帖子后,我仍然犯了这个错误,只是无法理解我遗漏了什么 以下是WCF web.config: <?xml version="1.0"?> <configuration> <appSettings> <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />

我的常见错误是MaxReceivedMessageSize为65536

在阅读了论坛上的一些相关帖子后,我仍然犯了这个错误,只是无法理解我遗漏了什么

以下是WCF web.config:

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>

  <system.serviceModel>

  <bindings>
    <basicHttpBinding>
      <binding name="ExtendedMaxSize"
          maxBufferSize="999999" maxReceivedMessageSize="999999" />
    </basicHttpBinding>
  </bindings>
  <services>
    <service name="WCFHaifaNetMobile.Service1" behaviorConfiguration="">

      <endpoint address=""
                binding="basicHttpBinding"
                bindingConfiguration="ExtendedMaxSize"
                contract="WCFHaifaNetMobile.IService1" />
    </service>
  </services>


    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" 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="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="wsHttpBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

我的MVC 4应用程序配置文件:

<?xml version="1.0"?>



<configuration>

  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>

  </configSections>


  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <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" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true"/> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/> 
  </appSettings>

  <system.web>
      <customErrors mode="Off">
    </customErrors>

    <httpHandlers>
      <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
    </httpHandlers>


    <!--
        Enabling request validation in view pages would cause validation to occur
        after the input has already been processed by the controller. By default
        MVC performs request validation before a controller processes the input.
        To change this behavior apply the ValidateInputAttribute to a
        controller or action.
    -->
    <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />

    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>
<system.serviceModel>

  <bindings>
    <basicHttpBinding>
      <binding name="ExtendedMaxSize"
          maxBufferSize="999999" maxReceivedMessageSize="999999" />
    </basicHttpBinding>
  </bindings>
  <services>
    <!-- some how HaifanetMobile.ServiceClient1 is not valid-->
    <service name="HaifanetMobile.ServiceClient1" behaviorConfiguration="">

      <endpoint address=""
                binding="basicHttpBinding"
                bindingConfiguration="ExtendedMaxSize"
                contract="ServiceClient1.IService1" />
    </service>
  </services>

</system.serviceModel>
</configuration>

如果MaxReceivedMessageSize为65536时出现错误,则:

  • 检查服务器和客户端配置,并在两侧将maxReceivedMessageSize和maxBufferSize设置为相同的值
  • 如果错误仍然存在,请检查您是否编辑了正确的配置文件
  • 如果错误仍然存在,请检查绑定是否是您正在使用的绑定
  • 如果错误仍然存在,请启动wcf跟踪:,这将准确地告诉您错误配置是在服务器上还是在客户端上