首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >增加WCF服务中的超时值

增加WCF服务中的超时值
EN

Stack Overflow用户
提问于 2009-01-08 14:12:40
回答 4查看 200.6K关注 0票数 138

如何在WCF服务上将默认超时时间增加到大于1分钟?

EN

回答 4

Stack Overflow用户

发布于 2009-01-08 14:21:53

在Visual Studio2008(或者2005,如果你安装了正确的WCF工具)的Tools菜单下,有一个叫做'WCF服务配置编辑器‘的选项。

在那里,您可以更改客户端和服务的绑定选项,其中一个选项将用于超时。

票数 45
EN

Stack Overflow用户

发布于 2017-01-18 22:48:31

您可以选择两种方式:

1)通过客户端的代码

代码语言:javascript
复制
public static void Main()
{
    Uri baseAddress = new Uri("http://localhost/MyServer/MyService");

    try
    {
        ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService));

        WSHttpBinding binding = new WSHttpBinding();
        binding.OpenTimeout = new TimeSpan(0, 10, 0);
        binding.CloseTimeout = new TimeSpan(0, 10, 0);
        binding.SendTimeout = new TimeSpan(0, 10, 0);
        binding.ReceiveTimeout = new TimeSpan(0, 10, 0);

        serviceHost.AddServiceEndpoint("ICalculator", binding, baseAddress);
        serviceHost.Open();

        // The service can now be accessed.
        Console.WriteLine("The service is ready.");
        Console.WriteLine("Press <ENTER> to terminate service.");
        Console.WriteLine();
        Console.ReadLine();

    }
    catch (CommunicationException ex)
    {
        // Handle exception ...
    }
}

2)在web服务器中使用WebConfig

代码语言:javascript
复制
<configuration>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding openTimeout="00:10:00" 
                 closeTimeout="00:10:00" 
                 sendTimeout="00:10:00" 
                 receiveTimeout="00:10:00">
        </binding>
      </wsHttpBinding>
    </bindings>
  </system.serviceModel>

有关更多细节,请查看官方文档

Configuring Timeout Values on a Binding

Class WSHttpBinding

票数 13
EN

Stack Overflow用户

发布于 2010-08-06 02:14:06

不同的超时意味着不同的事情。当你在客户机上工作时..您可能主要在查看SendTimeout -请查看此参考资料-精彩且相关的解释:http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/84551e45-19a2-4d0d-bcc0-516a4041943d/

上面写着:

代码语言:javascript
复制
Brief summary of binding timeout knobs...

Client side:

SendTimeout is used to initialize the OperationTimeout, which governs the whole interaction for sending a message (including receiving a reply message in a request-reply case).  This timeout also applies when sending reply messages from a CallbackContract method.
OpenTimeout and CloseTimeout are used when opening and closing channels (when no explicit timeout value is passed).
ReceiveTimeout is not used.

Server side:

Send, Open, and Close Timeout same as on client (for Callbacks).
ReceiveTimeout is used by ServiceFramework layer to initialize the session-idle timeout.
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/424358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档