gpt4 book ai didi

wcf channelfactory 和 opentimeout

转载 作者:行者123 更新时间:2023-12-04 15:02:44 26 4
gpt4 key购买 nike

在客户端,我试图连接到 WCF 更改 OpenTimeout属性设置为 5 秒,但它不起作用......这是我创建 channel 的方式:

NetTcpBinding bind = new NetTcpBinding(SecurityMode.None);
bind.OpenTimeout = new TimeSpan(0, 0, 5);
var channel = new ChannelFactory<IService>(bind, new EndpointAddress(myAddr));
channel.CreateChannel();

在此之后,我正在调用该方法,但如果服务器已关闭,则需要 21 秒而不是我在 OpenTimeout 上更改的 5 秒。 ,我错过了什么吗?

塔克斯

最佳答案

我用下一个方法解决了这个问题。好像是作品。

    protected TServiceContract CreateChannel()
{
TServiceContract channel = factory.CreateChannel();

var ar = ((IChannel)channel).BeginOpen( null, null );

if( !ar.AsyncWaitHandle.WaitOne( factory.Endpoint.Binding.OpenTimeout, true ) )
{
throw new TimeoutException( "Service is not available" );
}

((IChannel)channel).EndOpen( ar );

return channel;
}

关于wcf channelfactory 和 opentimeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8953112/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com