我有以下代码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