WCF服务-404.13错误-尽管设置了maxAllowedContentLength和maxRequestLength [英] WCF Service - 404.13 error - though maxAllowedContentLength and maxRequestLength are set

查看:93
本文介绍了WCF服务-404.13错误-尽管设置了maxAllowedContentLength和maxRequestLength的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对WCF服务还很陌生,但是当上传的文件太大而无法上传时,我就遇到了这个已知问题.我的情况很奇怪,因为我将 maxAllowedContentLength maxRequestLength 都设置了一个很高的数字,所以上传300 MB文件应该没有问题...对于小文件,它可以完美地工作,因此对我来说似乎只是忘记了我的设置.我尝试了很多想法来解决此问题,所以也许我弄乱了配置文件中的内容,可能有一些不必要的部分,但仍然找不到解决方案.

I'm quite new to WCF services, and I just ran into this known issue, when the uploaded file is too big to upload. My situation is strange because I set both maxAllowedContentLength and maxRequestLength to a high number, so it should have no problems with uploading 300 MB files... With small files it works perfectly, so for me it seems like it just forgets about my settings. I tried so many ideas to solve this problem, so maybe I messed up things in my config file, there may be some unnecessary parts, but still I couldn't find the solution.

我正在使用IIS 10和.Net 4.5.

I'm working with IIS 10 and .Net 4.5.

我的WCF服务配置:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" maxRequestLength="4048576" requestLengthDiskThreshold="4048576" executionTimeout="3600" />
</system.web>
<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="TileServiceBehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
    <behavior name="FileUploadServiceBehavior">
      <serviceMetadata httpGetEnabled="True" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_ITileService" sendTimeout="01:00:00" maxBufferSize="5000000" /> 
    <binding name="HttpBinding_MTOM" 
              messageEncoding="Text" 
              transferMode="Streamed" 
              maxReceivedMessageSize="4294967294" 
              maxBufferSize="65536" 
              maxBufferPoolSize="65536" />
    <binding name="BasicHttpBinding_ITileServiceUpload" 
                closeTimeout="00:01:00" 
                openTimeout="00:01:00" 
                receiveTimeout="00:10:00" 
                sendTimeout="00:10:00" 
                allowCookies="false" 
                bypassProxyOnLocal="false" 
                hostNameComparisonMode="StrongWildcard" 
                maxBufferSize="65536" 
                maxBufferPoolSize="524288" 
                maxReceivedMessageSize="4294967294" 
                messageEncoding="Text" 
                textEncoding="utf-8" 
                transferMode="Streamed" 
                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://localhost/AEGIS.TileService/TileService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITileServiceUpload" contract="AEGIS.TileService.ITileService" name="BasicHttpBinding_ITileServiceUpload" />
</client>
<services>
  <service behaviorConfiguration="FileUploadServiceBehavior" name="AEGIS.TileService.TileService">
    <endpoint address="winceStream" binding="basicHttpBinding" bindingConfiguration="HttpBinding_MTOM" contract="AEGIS.TileService.ITileService" />
  </service>
</services>
</system.serviceModel>
  <system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
<security>
  <requestFiltering>
    <requestLimits maxAllowedContentLength="4294967295" maxUrl="4294967295" maxQueryString="4294967295" />
  </requestFiltering>
</security>

我的ASP.NET Web应用程序中引用了该服务的web.config文件.

The web.config file from my ASP.NET web app, where the service is referenced.

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_ITileService"/>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost/AEGIS.TileService/TileService.svc/winceStream" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITileService" contract="TileService.ITileService" name="BasicHttpBinding_ITileService"/>
</client>

我的上传方法是这样实现的:

My upload method is implemented like this:

public void UploadFile(FileUploadMessage request)
    {
        string basePath = AppDomain.CurrentDomain.BaseDirectory + @"\Images\";
        string serverFileName = Path.Combine(basePath, request.Filename);

        using (FileStream outfile = new FileStream(serverFileName, FileMode.Create))
        {
            const int bufferSize = 65536; // 64K
            Byte[] buffer = new Byte[bufferSize];
            int bytesRead = request.FileByteStream.Read(buffer, 0, bufferSize);
            while (bytesRead > 0)
            {
                outfile.Write(buffer, 0, bytesRead);
                bytesRead = request.FileByteStream.Read(buffer, 0, bufferSize);
            }
        }
    }

FileUploadMessage是这样的:

Where FileUploadMessage is like this:

[MessageContract]
public class FileUploadMessage
{
    [MessageHeader(MustUnderstand = true)]
    public string Filename;
    [MessageBodyMember(Order = 1)]
    public Stream FileByteStream;
}

我找到了有关此问题的这篇文章.也许我的问题不是WCF服务或配置,而是IIS?

I found this article about this issue. Maybe my problem is not with the WCF service or config, but with IIS?

我还将默认应用程序池的requestLimits也设置为1000000000.错误仍然出现.

I set the requestLimits of the Default App Pool also to 1000000000. The error still appears.

此外,在选项3中,文章还介绍了有关更改ApplicationHost.config的内容.奇怪的是,该文件中没有关于requestLimits的任何内容.也许这是主要问题?

Also in Option 3 the article writes about changing the ApplicationHost.config. The strange thing is that I don't have anything in that file about requestLimits. Maybe that's the main problem?

推荐答案

您可能正在处理多个问题".

Your are probably dealing with multiple "issues".

请记住要相应地配置服务器和客户端!

首先,我将配置.NET运行时(WCF)和IIS行为 https://stackoverflow.com/a/6472631/1498669

First, i would configure my .NET runtime (WCF) and IIS behavior https://stackoverflow.com/a/6472631/1498669

注意:maxRequestLength位于 KILOBYTES 中,而maxAllowedContentLength位于 BYTES

NOTE: maxRequestLength is in KILOBYTES whereas maxAllowedContentLength is in BYTES

我会

  1. 为您的特定应用程序设置默认的IIS参数 (不是为整个计算机设置!)在基本Web文件夹中使用web.config 设置为相对"较高的值
  1. set the default IIS parameter for your specific application (not for the whole machine!) using web.config in your base webfolder to a 'relatively' high value

<system.webServer>
 <security>
  <requestFiltering>

   <!-- maxAllowedContentLength defaults to 30000000 BYTES = 30MB --> 
   <!-- i use 100MB (100 *1024*1024)-->

   <requestLimits maxAllowedContentLength="104857600" /> 
  </requestFiltering> 
 </security>
</system.webServer>

  • https://support.microsoft.com/en-us/kb/944981
  • https://msdn.microsoft.com/en-us/library/ms689462.aspx
    1. 将.NET Framework参数设置为以KB为单位的我期望的最大"值(至少比iis值低一点),以便能够在iis向我显示错误网站之前捕获异常(注意:还可以增加超时时间)大数据传输).

    <system.web>
    
     <!-- maxRequestLength defaults to 4096 KILOBYTES = 4MB -->
     <!-- i use 80MB (80 *1024) -->
     <!-- please notes that if you use base64 encoded messages -->
     <!-- you have to calculate the overhead with CEIL(nBytes/3)*4 -->
     <!-- executionTimeout defaults to 110 SECONDS, i use 5 minutes -->
    
     <httpRuntime maxRequestLength="81920" executionTimeout="600" /> 
    </system.web>
    

    • https://support.microsoft.com/en-us/kb/295626
    • https://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.maxrequestlength.aspx
    • https://msdn.microsoft.com/en-us/library/e1f13641(v = vs.100).aspx
      1. 之后,我配置端点及其绑定

      https://msdn.microsoft.com/en-us/library/ms733865.aspx

      有关不同的属性及其含义,另请参见 https://stackoverflow.com/a/36931852/1498669 .

      Also see https://stackoverflow.com/a/36931852/1498669 for the different attributes and their meaning.

      作为参考,计算机web.config位于(取决于您是否使用2.0/4.0和32/64位):

      As reference, the machine web.configs are located in (depending if you are using 2.0/4.0 and 32/64bits):

      • 32位/net2.0-3.5
        C:\ Windows \ Microsoft.NET \ Framework \ v2.0.50727 \ Config \ web.config
      • 32位/net4.x
        C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Config \ web.config
      • 64位/net2.0-3.5
        C:\ Windows \ Microsoft.NET \ Framework64 \ v2.0.50727 \ Config \ web.config
      • 64位/net4.x-这主要用于Server2008R2和更高版本中
        C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Config \ web.config

      在这些目录中也有:

      • web.config.default -如果您无意中更改了计算机配置,则可以通过 web.config 复制该代码以重置计算机配置!
      • web.config.comments -有关属性/元素的具体说明
      • web.config.default - you can copy that over web.config to reset your machine config, if you unintentionally altered the machine config!
      • web.config.comments - for a specific explanation of the attrs/elements

      如果您想联系所有可用的元素/属性,请查阅您的Visual Studio安装目录,例如:

      If you want to get in touch to all available elements/attributes - consult your visual studio installation directory, e.g:

      C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Xml \ Schemas \ DotNetConfig45.xsd

      C:\Program Files (x86)\Microsoft Visual Studio 14.0\Xml\Schemas\DotNetConfig45.xsd


      主题:作为安全设置的附加信息,请参见 https://msdn.microsoft.com/en-us/library/ff648505.aspx

      这篇关于WCF服务-404.13错误-尽管设置了maxAllowedContentLength和maxRequestLength的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆