我有一个WCF服务,它有一个非常耗时的方法,可以将大数据文件上传到“azure table 存储”。
我在运行时在客户端设置我的超时,如下所示: -
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);
答案 0 :(得分:0)
对于文件上传,还有一些其他配置需要到位。首先,您要上传的文件有多大?如果他们是>大约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>
答案 1 :(得分: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;
}
}