1

画像をアップロードするためのWCFサービスを作成しました。さまざまな小さな画像で問題なく動作します。しかし、800KBのような画像で試してみると、「リモートサーバーがエラーを返しました:(400)不正なリクエスト」というメッセージが表示されます。ログファイルを見ると、次の例外があります。ThrowMaxReceivedMessageSizeExceeded()年齢を探していて、maxRequestLengthの設定やその他のいくつかの設定など、さまざまなことを試しました。

私のサイトにはWCFApp、WebApplocation、サービス参照を持つBLClientにはclassLibraryがあります。

これらは私の設定ファイルです:

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>

Webアプリケーションの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

小切手

classLibraryのApp.configのhttpTransport要素に存在する場合:

maxReceivedMessageSize="104857600"
于 2012-07-05T16:42:30.993 に答える