如何在 Castle Windsor WcfClient 上设置超时 属性
How do I set Timeout property on Castle Windsor WcfClient
我有一个 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>
干杯
您可以直接在绑定上设置属性:
var timeout = new TimeSpan(0, 0, 10, 0);
var binding = new NetTcpBinding(SecurityMode.None)
{
CloseTimeout = timeout,
ReceiveTimeout = timeout,
SendTimeout = timeout,
OpenTimeout = timeout
};
然后:
.BoundTo(binding)
我有一个 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>
干杯
您可以直接在绑定上设置属性:
var timeout = new TimeSpan(0, 0, 10, 0);
var binding = new NetTcpBinding(SecurityMode.None)
{
CloseTimeout = timeout,
ReceiveTimeout = timeout,
SendTimeout = timeout,
OpenTimeout = timeout
};
然后:
.BoundTo(binding)