【问题标题】:How do I set Timeout property on Castle Windsor WcfClient如何在 Castle Windsor WcfClient 上设置 Timeout 属性
【发布时间】:2017-11-28 09:49:22
【问题描述】:

我有一个 Windows 服务,我正在像这样调用 Wcf 客户端端点。

        Console.WriteLine("Invoking start...");
        using (var container = new WindsorContainer())
        {
            container.AddFacility<WcfFacility>();
            container.Register(
                Component.For<IShoppingService>()                        
                    .AsWcfClient(new DefaultClientModel(
                        WcfEndpoint
                            .ForContract<IShoppingService>()
                            .BoundTo(new NetTcpBinding(SecurityMode.None))
                            .At("net.tcp://localhost:12123/shoppingService"))));
            container.Resolve<IShoppingService>().Debug();
        }
        Console.WriteLine("Invoking end...");

出于调试目的,我想以编程方式将调用的超时时间增加到 10 分钟。如何像通常在 app.config 文件的绑定部分中那样在客户端上设置超时属性,就像这样

  <system.serviceModel>
<bindings>
  <netTcpBinding>
    <binding name="longTimeOutLargeTcpBuffer" maxBufferSize="20000000" maxReceivedMessageSize="20000000" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00">
      <readerQuotas maxArrayLength="20000000" maxBytesPerRead="20000000" maxStringContentLength="10000000" />
      <security mode="None" />
    </binding>        
  </netTcpBinding>
</bindings>

干杯

【问题讨论】:

    标签: c# .net wcf castle-windsor wcf-binding


    【解决方案1】:

    您可以直接在绑定上设置属性:

        var timeout = new TimeSpan(0, 0, 10, 0);
        var binding = new NetTcpBinding(SecurityMode.None)
                          {
                              CloseTimeout = timeout,
                              ReceiveTimeout = timeout,
                              SendTimeout = timeout,
                              OpenTimeout = timeout
                          };
    

    然后:

        .BoundTo(binding)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-26
      • 2011-08-17
      相关资源
      最近更新 更多