当所有超时参数设置为最大值时,WCF服务超时
我有一个WCF服务,它有一个非常耗时的方法,可以将大数据文件上传到“azure 表存储”。当所有超时参数设置为最大值时,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);
对于文件上传,还有一些其他配置需要到位。首先,您试图上传的文件有多大?如果它们大于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>
我使用类似的azure blob来存储我的内容。我的代码没有任何timout设置。试试这个,让我知道。
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表格存储之前,我需要做相当多的处理,所以我认为这不适用 – ChrisW 2013-02-27 16:23:28
感谢您的信息,这些属性与传输到服务器端的文件大小有关吗?如果是这样,我不认为他们是问题,我测试的文件是4.5MB。这是压缩的大小,我在服务器上解压缩和处理,这是耗时的部分。 – ChrisW 2013-02-27 16:21:32
嗯,这取决于抛出错误的位置。你知道,如果你的上传请求实际上对服务有用吗?在我的非Azure WCF应用程序中,当我收到文件上传中提到的错误时,这是因为Web服务器的默认内容长度太小。在服务器端使用上面的配置,我能够上传文件。即使你有几个MB,默认大小通常也太小。这是WCF消息大小的单独配置。 – 2013-02-27 16:55:47
这是另一个解释它的问题:http://stackoverflow.com/questions/6327452/which-gets-priority-maxrequestlength-or-maxallowedcontentlength。您是使用IIS还是直接发布到Azure? – 2013-02-27 16:57:25