1

我创建了一个 WCF 服务来上传图像。它适用于各种小图像。但是当我尝试使用 800KB 之类的图像时,我得到“远程服务器返回错误:(400)错误请求。” 当我查看日志文件时,我看到了这个异常: ThrowMaxReceivedMessageSizeExceeded() 我一直在寻找年龄并尝试了很多不同的东西,包括设置 maxRequestLength 和其他几个设置。

我有 WCFApp、WebApplocation-用于我的站点,以及 classLibrary-用于具有服务参考的 BLClient。

这些是我的配置文件:

WCFApplication 的 Web.config:

 <?xml version="1.0"?>
     <configuration>
  <connectionStrings>
    <add name="photoShopEntities"
         connectionString="metadata=res://*/photoShop.csdl|
         res://*/photoShop.ssdl|
         res://*/photoShop.msl;
         provider=System.Data.SqlClient;provider connection string='Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|photoShop.mdf;Integrated Security=True;User Instance=True'"
         providerName="System.Data.EntityClient" />
  </connectionStrings>
  <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="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

WebApplication 的 Web.config:

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <connectionStrings>
    <add name="ApplicationServices"
         connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />

    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </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="true">
      <providers>
        <clear />
        <add connectionStringName="ApplicationServices" applicationName="/"
          name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
        <add applicationName="/" name="AspNetWindowsTokenRoleProvider"
          type="System.Web.Security.WindowsTokenRoleProvider" />
      </providers>
    </roleManager>


  </system.web>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>



  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IBLServer" 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:50739/PhotoShopWS.svc" binding="basicHttpBinding"
          bindingConfiguration="BasicHttpBinding_IBLServer" contract="PhotoShopWS.IBLServer"
          name="BasicHttpBinding_IBLServer" />
    </client>
  </system.serviceModel>
</configuration>

classLibrary 的 App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IBLServer" 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:50739/PhotoShopWS.svc" binding="basicHttpBinding"
          bindingConfiguration="BasicHttpBinding_IBLServer" contract="PhotoShopWS.IBLServer"
          name="BasicHttpBinding_IBLServer" />
    </client>
  </system.serviceModel>
</configuration>

我看到了很多关于它的答案,但我的问题仍然存在。任何帮助是极大的赞赏!

4

3 回答 3

3

在 WCF 应用程序的 web.config 中,您必须将其指定maxReceivedMessageSize为更高的值。

前任。

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
             <binding transferMode="Streamed"
                     maxReceivedMessageSize="67108864">
               <!-- other config here -->
            </binding>
        </basicHttpBinding>
    </bindings>
</system.serviceModel>
于 2012-07-06T03:34:18.927 回答
1

我使用了标记帮助,现在我的网站允许上传大图像。

这是更改后我的 WCFApplication 的 web.config。

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="photoShopEntities"
         connectionString="metadata=res://*/photoShop.csdl|
         res://*/photoShop.ssdl|
         res://*/photoShop.msl;
         provider=System.Data.SqlClient;provider connection string='Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|photoShop.mdf;Integrated Security=True;User Instance=True'"
         providerName="System.Data.EntityClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime maxRequestLength="2147483647"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding transferMode="Streamed"
                maxReceivedMessageSize="67108864">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
            maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <!-- other config here -->
        </binding>
      </basicHttpBinding>
    </bindings>
    <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="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

非常感谢!!

于 2012-07-06T09:43:07.993 回答
0

查看

如果它存在于 httpTransport 元素中,则在 classLibrary 的 App.config 中:

maxReceivedMessageSize="104857600"
于 2012-07-05T16:42:30.993 回答