[英]WCF timeout problem using net.tcp binding with callbacks
我正在使用 net.tcp 绑定通过回调数据向客户端发送(在客户端“注册”之后) - 问题是连接超时 - 当我稍后调用取消连接的方法时(设置数据库中的一列)我收到错误,由于安全上下文令牌无效或服务因不活动而中止通道而导致连接出现故障 - 但我已经将 receiveTimeout 设置为 TimeSpan.MaxValue ...
ServiceHost host;
...
var prog = new Program();
prog.host = new ServiceHost(typeof(DataService), new Uri[] { new Uri("net.tcp://localhost:50111") });
prog.StartServer();
...
private void StartServer()
{
NetTcpBinding binding = new NetTcpBinding();
binding.OpenTimeout = new TimeSpan(0, 0, 30);
binding.CloseTimeout = new TimeSpan(0, 0, 30);
binding.SendTimeout = new TimeSpan(0, 0, 30);
binding.ReceiveTimeout = TimeSpan.MaxValue;
OptionalReliableSession reliableSession=binding.ReliableSession;
reliableSession.Enabled = true;
reliableSession.Ordered = true;
reliableSession.InactivityTimeout = new TimeSpan(0, 0, 15);
this.host.AddServiceEndpoint(typeof(IDataService), binding, "DataService");
this.host.Open();
}
客户端上的代码使用相同的连接参数(超时等)
如何在故意关闭之前保持连接?
NetTcpbinding 默认使用 Windows 身份验证来保护通信。 下面的定义是等价的。
NetTcpBinding binding = new NetTcpBinding();
NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
当客户端调用服务时,我们应该提供一对 Windows 凭据以供服务器进行身份验证。
ServiceReference1.Service1Client client = new Service1Client();
//provides windows credentials in order to be authenticated by the server.
//these credentials actually are the windows account on the server-side.
client.ClientCredentials.Windows.ClientCredential.UserName = "administrator";
client.ClientCredentials.Windows.ClientCredential.Password = "abcd1234!";
在我看来,如果我们不提供 Windows 凭据,调用将导致超时异常。 如果问题仍然存在,请随时告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.