我有一个WCF服务,它有一个非常耗时的方法,将大数据文件上传到"azure 表存储"。
我在客户端运行时设置超时如下:-
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);
和我的网。配置的超时设置如下:—
<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);
我使用类似的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;
}
}
对于文件上传,还需要准备一些其他配置。首先,你要上传的文件有多大?如果它们> 50MB左右,您可能需要将它们分成更小的块并发送这些块。
在此之前,尝试将以下设置添加到配置中。不要担心<authentication>
和<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>