1

我有一个自托管的 WCF 服务。当 InstanceContextMode 设置为 PerCall 时,它工作得很好,除了速度很慢。(构造函数很重,所以很有意义)我将 InstanceContextMode 设置为 Single,现在它工作正常,在服务启动后。但是,如果服务仍在启动,我会收到有关未找到端点的错误。当我在 PerCall 模式下运行时,这并没有发生。有什么办法可以让请求等待更长时间以等待服务启动?我尝试在绑定上设置 OpenTimeout、ReceiveTimeout 和 SendTimeout,但无济于事。

这是我的调用代码:

try
{
    ChannelFactory<IGatewayService> scf;
    var binding = new NetTcpBinding();
    binding.Security.Mode = SecurityMode.None;
    scf = new ChannelFactory<IGatewayService>(binding, "net.tcp://" + settings.GatewayHost + ":" + settings.GatewayPort);
    IGatewayService s;
    s = scf.CreateChannel();
    result = s.Submit(taskToSubmit);
    (s as ICommunicationObject).Close();
}
catch (Exception exc)
{
    if (log.IsErrorEnabled) { log.Error("Error submitting task to Gateway", exc); }
}

PS。我是 WCF 菜鸟,但我相信你们现在都明白了;)

4

0 回答 0