[英]WCF timeout problem using net.tcp binding with callbacks
I'm using a net.tcp binding to send via callback data to the client (after client once "signed up" ) - problem is that the connection runs into time out - and when I later call a method to cancel the connection (sets a column in database) I receive errors, that the connection is faulted due to either security context token being invalid or service aborted the channel due to inactivity - but I already set the receiveTimeout to TimeSpan.MaxValue...我正在使用 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();
}
code on the client is using same connection parameters (timeout and so on)客户端上的代码使用相同的连接参数(超时等)
How can I keep the connection alive until closing it willfully?如何在故意关闭之前保持连接?
NetTcpbinding secures the communication by using Windows authentication by default. NetTcpbinding 默认使用 Windows 身份验证来保护通信。 The below definition is equivalent.
下面的定义是等价的。
NetTcpBinding binding = new NetTcpBinding();
NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
When the client calls the service, we should provide a pair of windows credentials to be authenticated by the server.当客户端调用服务时,我们应该提供一对 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!";
In my opinion, the invocation will result in the timeout exception if we do not provide the windows credential.在我看来,如果我们不提供 Windows 凭据,调用将导致超时异常。 Feel free to let me know if the problem still exists.
如果问题仍然存在,请随时告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.