【问题标题】:WCF service timing out when all timeout parameters set to maximum当所有超时参数设置为最大值时 WCF 服务超时
【发布时间】:2013-02-26 11:37:14
【问题描述】:

我有一个 WCF 服务,它有一个非常耗时的方法,将大数据文件上传到“azure table storage”。

我在客户端运行时设置超时如下:-

binding = new BasicHttpBinding();
binding.CloseTimeout = TimeSpan.FromMilliseconds(2147483647.0);
binding.OpenTimeout = TimeSpan.FromMilliseconds(2147483647.0);
binding.ReceiveTimeout = TimeSpan.FromMilliseconds(2147483647.0);
binding.SendTimeout = TimeSpan.FromMilliseconds(2147483647.0);

我的 web.config 的超时设置如下:-

<bindings>
      <basicHttpBinding>
        <binding maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" sendTimeout="22:30:00" receiveTimeout="22:30:00" openTimeout="22:30:00" closeTimeout="22:30:00" maxBufferSize="2147483647">
          <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>

我在 VS 2012 中运行我的代码,我看到的问题是文件上传方法在 60 分钟后崩溃,出现未处理的 CommunicationException:远程服务器返回错误:NotFound。如果我按 F5,则上传继续并完成。此时崩溃出现在Reference.cs文件中:-

public void EndFileUploadMethod(System.IAsyncResult result) {
                object[] _args = new object[0];
                base.EndInvoke("FileUploadMethod", _args, result);

【问题讨论】:

    标签: wcf azure


    【解决方案1】:

    我使用类似的 azure blob 来存储我的内容。我的代码没有任何超时设置。试试这个,让我知道。

        public static CloudBlobContainer Container
        {
            get
            {
                CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
                    {
                        // Provide the configSetter with the initial value
                        configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
                        RoleEnvironment.Changed += (sender, arg) =>
                        {
                            if (arg.Changes.OfType<RoleEnvironmentConfigurationSettingChange>().Any((change) =>
                            (change.ConfigurationSettingName == configName)))
                            {
                                // The corresponding configuration setting has changed, so propagate the value
                                if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
                                {
                                    // In this case, the change to the storage account credentials in the
                                    // service configuration is significant enough that the role needs to be
                                    // recycled in order to use the latest settings (for example, the 
                                    // endpoint may have changed)
                                    RoleEnvironment.RequestRecycle();
                                }
                            }
                        };
                    });
                CloudStorageAccount acc = CloudStorageAccount.FromConfigurationSetting("RecordingsStorageAccount");
                CloudBlobClient bc = acc.CreateCloudBlobClient();
                CloudBlobContainer c = bc.GetContainerReference(RoleEnvironment.GetConfigurationSettingValue("RecordingsContainer"));
                return c;
            }
        }
    

    【讨论】:

    • 在将文件内容传输到 azure table 存储之前,我需要做一些处理,所以我认为这不适用
    【解决方案2】:

    对于文件上传,还需要进行一些其他配置。首先,您要上传的文件有多大?如果它们 > 50MB 左右,您可能需要将它们分成小块并发送过来。

    在此之前,请尝试将以下设置添加到您的配置中。不要担心&lt;authentication&gt;&lt;compilation&gt; 标签。感兴趣的是&lt;httpRuntime&gt;&lt;requestLimits&gt; 标签。

    我的maxAllowedContentLength 属性值在下面是任意的,因此您可以将其设置为您想要的任何值。我相信它是以字节为单位的。

      <system.web>
        <compilation debug="true" targetFramework="4.0"/>
        <authentication mode="Windows" />
        <httpRuntime maxRequestLength="2147483647" />
      </system.web>
    
      <system.webServer>
        <security>
          <requestFiltering>
            <requestLimits maxAllowedContentLength="2000000000" />
          </requestFiltering>
        </security>
      </system.webServer>
    

    【讨论】:

    • 感谢您的信息,这些属性是否与传输到服务器端的文件大小限制有关?如果是这样,我认为它们不是问题,我正在测试的文件是 4.5MB。那是压缩后的大小,我在服务器上解压和处理,这是耗时的部分。
    • 嗯,这取决于抛出错误的位置。你知道你的上传请求是否真的进入了服务吗?在我的非天蓝色 WCF 应用程序中,当我收到文件上传时提到的错误时,这是​​因为 Web 服务器的默认内容长度太小。在服务器端使用上面的配置,我能够上传文件。即使您有几 MB,默认大小通常也太小了。这是与 WCF 消息大小分开的配置。
    • 这是另一个解释它的问题:stackoverflow.com/questions/6327452/…。您是使用 IIS 还是直接发布到 Azure?
    • 该服务肯定已经到达,因为它通过文件上传完成了大约 35%。当我上次运行上传时,我有 maxRequestLength="2147483647" 和 maxAllowedContentLength="4294967295"(以前,maxAllowedContentLength 是 2000000000),我在一小时后经历了同样的崩溃。我没有使用 IIS,直接发布到 Azure。
    猜你喜欢
    • 2013-08-23
    • 2013-05-18
    • 2011-06-04
    • 1970-01-01
    • 2010-10-17
    • 2012-03-23
    • 2010-09-18
    • 2013-01-15
    相关资源
    最近更新 更多