我有以下代碼WCF超時問題
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屬性) ,並確保該服務能夠 連接到客戶端。
如何以不同於我爲避免此錯誤的方式來投射頻道,這很有意義,因爲底層請求可能需要一分多鐘才能計算。
這似乎沒有解決問題。 – PlTaylor 2011-02-24 18:48:36