0

我有一个 WCF 服务,它有一个非常耗时的方法,将大数据文件上传到“天蓝色存储”。

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

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);
4

2 回答 2

0

我使用类似的 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;
        }
    }
于 2013-02-26T14:27:04.463 回答
0

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

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

我的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>
于 2013-02-26T14:21:04.640 回答