远程服务器返回错误:(413)请求实体太大WCF

问题描述 投票:0回答:1

我有一个Windows应用程序,可以使用WCF服务将图像发送到服务器。当我运行代码并上传图像时,WCF返回“远程服务器返回错误:(413)请求实体太大。”

我从链接中尝试了几种方法,但没有解决。

以下是我的WCF配置。

<configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation targetFramework="4.5.2" />
    <httpRuntime maxRequestLength="2147483647" />
  </system.web>
  <system.serviceModel>
    <bindings>
       <basicHttpBinding>
        <binding name="secureHttpBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="Transport" />
        </binding>

        </basicHttpBinding>
    </bindings>
    <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="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>

以下是Windows应用程序中的app.config。

    <system.serviceModel>
        <bindings>
      <basicHttpBinding>

        <binding name="BasicHttpBinding_ILicencePhoto" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
          maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="Transport" />
        </binding>

       <binding name="BasicHttpBinding_IUserLogging" >
          <security mode="Transport" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>

          <endpoint address="https://xxxxx/wcf/image.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ILicencePhoto"
        contract="LicencePhoto.ILicencePhoto" name="BasicHttpBinding_ILicencePhoto" />       

 <endpoint address="https://xxxxx/wcf/user.svc" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_IUserLogging" contract="UserLogging.IUserLogging"
        name="BasicHttpBinding_IUserLogging" />
    </client>
  </system.serviceModel>

我可以通过调用userWCF登录。问题是将用户照片上传到WCF服务时。用户照片文件的大小最大约为500KB。

谢谢。尼尼昂昂

wcf-binding
1个回答
1
投票

主要问题是我们没有在服务器端应用配置。由于服务器端使用ProtocolMapping功能来使服务能够通过HTTPS协议工作,因此我们应该在BasicHttpsBinding而不是BasicHttpBinding上修改并应用配置。请参考以下配置(服务器端)。

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="secureHttpBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="Transport" />
        </binding>
      </basicHttpBinding>
      <basicHttpsBinding>
        <binding name="httpsBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="Transport" />
        </binding>
      </basicHttpsBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" bindingConfiguration="httpsBinding"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

随时让我知道问题是否仍然存在。

© www.soinside.com 2019 - 2024. All rights reserved.