c# - 对同一 WCF 服务的不同请求的不同超时

标签 c# wcf timeout .net-4.5

我有一个带有 https 绑定(bind)和回调的 WCF 服务。该服务在客户端中作为服务引用进行引用。超时在服务和客户端的配置文件中定义。

我需要在服务中调用一个函数,其超时值比其他函数使用的默认值更小。

我的客户的代码如下所示

MyService.MyServiceClient myServiceClient = new MyService.MyServiceClient(context);
myServiceClient.GenericSendData("Save Req", serializedString, ServerIdentifier, null);

如何更改客户端/服务器中的代码,以便对特定功能的请求使用较小的超时值?我可以根据我调用的函数指定和更改代码中的超时吗?

最佳答案

是的。只需在客户端上设置 SendTimeout 即可。要为特定服务调用设置 10 秒超时,您可以使用以下示例:

using(MyService.MyServiceClient myServiceClient = new MyService.MyServiceClient(context))
{
    myServiceClient.Endpoint.Binding.SendTimeout = TimeSpan.FromSeconds(10);
    myServiceClient.GenericSendData("Save Req", serializedString, ServerIdentifier, null);
}

关于c# - 对同一 WCF 服务的不同请求的不同超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26360003/

相关文章:

c# - Service Fabric Owin 管道中的 WsFederation 身份验证不起作用

.net - 使用 Net.TCP 时在客户端添加 Web 引用

node.js - 为 HTTPS 设置超时的正确方法

javascript - 如何在 JavaScript 中的函数完成之前禁止单击按钮

Wcf客户端: Passing XML string in the WCF REST service using WebInvoke

oracle - 事务超时在 Oracle 的 Hibernate 上不起作用

c# - 在字典的值集合上应用函数

c# - 以编程方式安装服务而不打印调试信息

c# - 如何将 "IStorageItem"的实现传递给 DataPackage.SetStorageItems(items) 并且不在 UWP 上引发 InvalidCastException?

c# - 客户端通过 Internet 访问 SQL Server