簡體   English   中英

WCF超時問題

[英]WCF Timeout Problem

我有以下代碼

public bool StartWCF()
    {
        try
        {
            // Select the first entry. I hope it's this maschines IP
            // IPAddress _ipAddress = ips.AddressList[0];
            var ipAddress = new IPAddress(new byte[] { 127, 0, 0, 1 });

            // Create the url that is needed to specify where the service should be started
            this.m_UrlMetaServiceComm = "net.tcp://" + ipAddress + ":8000/VSMDBCommunication";
            this.m_UrlMetaServicePart = "net.tcp://" + ipAddress + ":8000/VSMDBPartType";

            string endPointAddrComm = this.m_UrlMetaServiceComm;
            var tcpBindingComm = new NetTcpBinding
                {
                    TransactionFlow = false,
                    MaxReceivedMessageSize = 20000000,
                    MaxBufferSize = 20000000,
                    MaxBufferPoolSize = 20000000,
                    ReaderQuotas = { MaxNameTableCharCount = 20000000 },
                    OpenTimeout = new TimeSpan(0, 5, 0),
                    SendTimeout = new TimeSpan(0, 5, 0),
                    CloseTimeout = new TimeSpan(0, 5, 0)
                };
            tcpBindingComm.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign;
            tcpBindingComm.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
            tcpBindingComm.Security.Mode = SecurityMode.None;

            var endpointAddressComm = new EndpointAddress(endPointAddrComm);
            this.m_ChannelCommunication = ChannelFactory<IVSMDBCommunication>.CreateChannel(
                tcpBindingComm, endpointAddressComm);
            ((IContextChannel)m_ChannelCommunication).OperationTimeout = new TimeSpan(0, 5, 0);
            string endPointAddrPart = this.m_UrlMetaServicePart;
            var tcpBindingPart = new NetTcpBinding
                {
                    TransactionFlow = false,
                    MaxReceivedMessageSize = 20000000,
                    MaxBufferSize = 20000000,
                    MaxBufferPoolSize = 20000000,
                    ReaderQuotas = { MaxNameTableCharCount = 20000000 },
                    OpenTimeout = new TimeSpan(0, 5, 0),
                    SendTimeout = new TimeSpan(0, 5, 0),
                    CloseTimeout = new TimeSpan(0, 5, 0)
                };
            tcpBindingPart.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign;
            tcpBindingPart.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
            tcpBindingPart.Security.Mode = SecurityMode.None;

            var endpointAddressPart = new EndpointAddress(endPointAddrPart);
            this.m_ChannelPartTypes = ChannelFactory<IVSMDBPartType>.CreateChannel(
                tcpBindingPart, endpointAddressPart);
            ((IContextChannel)m_ChannelPartTypes).OperationTimeout = new TimeSpan(0, 5, 0);
            return true;
        }
        catch (CommunicationObjectFaultedException faultEx)
        {
            // System.Diagnostics.Trace.TraceError(faultEx.ToString());
            Console.WriteLine("An unknown exception was received. " + faultEx.Message + faultEx.StackTrace);
            Console.Read();
            return false;
        }
        catch (EndpointNotFoundException endEx)
        {
            // System.Diagnostics.Trace.TraceError(endEx.ToString());
            Console.WriteLine("An unknown exception was received. " + endEx.Message + endEx.StackTrace);
            Console.Read();
            return false;
        }
    }

當基礎流程花費一分鍾以上的時間時,有時會出現以下錯誤。

信息:

發送到net.tcp://127.0.0.1:8000 / VSMDBCommunication的此請求操作在配置的超時(00:01:00)內未收到答復。 分配給該操作的時間可能是較長超時的一部分。 這可能是因為該服務仍在處理該操作,或者是因為該服務無法發送回復消息。 請考慮增加操作超時(通過將通道/代理轉換為IContextChannel並設置OperationTimeout屬性),並確保該服務能夠連接到客戶端。

我如何以與避免這種錯誤的方式不同的方式投射頻道,這是有道理的,因為基礎請求可能要花一分鍾多的時間才能計算出來。

將客戶端操作超時設置為

client.InnerChannel.OperationTimeout = TimeSpan.FromMinutes(10);

這將消除您的錯誤。

也嘗試設置ReceiveTimeout屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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