簡體   English   中英

使用帶有回調的 net.tcp 綁定的 WCF 超時問題

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM