Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF超时问题_C#_Wcf_Timeout - Fatal编程技术网

C# WCF超时问题

C# WCF超时问题,c#,wcf,timeout,C#,Wcf,Timeout,我有以下代码 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,

我有以下代码

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;
        }
    }
public bool StartWCF()
{
尝试
{
//选择第一个条目。我希望是这个机器IP
//IPAddress _IPAddress=ips.AddressList[0];
var-ipAddress=new-ipAddress(新字节[]{127,0,0,1});
//创建指定服务启动位置所需的url
this.m_UrlMetaServiceComm=“net.tcp://“+ipAddress+”:8000/VSMDBCommunication”;
this.m_UrlMetaServicePart=“net.tcp://”+ipAddress+“:8000/VSMDBPartType”;
字符串endPointAddrComm=this.m_UrlMetaServiceComm;
var tcpBindingComm=新的nettcpbindingcomm
{
TransactionFlow=false,
MaxReceivedMessageSize=20000000,
MaxBufferSize=20000000,
MaxBufferPoolSize=20000000,
ReaderQuotas={MaxNameTableCharCount=20000000},
OpenTimeout=新的时间跨度(0,5,0),
SendTimeout=新的时间跨度(0,5,0),
CloseTimeout=新的时间跨度(0,5,0)
};
tcpBindingComm.Security.Transport.ProtectionLevel=ProtectionLevel.EncryptAndSign;
tcpBindingComm.Security.Transport.ClientCredentialType=TcpClientCredentialType.Windows;
tcpBindingComm.Security.Mode=SecurityMode.None;
var endpointAddressComm=新的EndpointAddress(endPointAddrComm);
this.m_ChannelCommunication=ChannelFactory.CreateChannel(
tcpBindingComm、endpointAddressComm);
((IContextChannel)m_channel通信)。操作超时=新的时间跨度(0,5,0);
字符串endPointAddrPart=this.m_UrlMetaServicePart;
var tcpBindingPart=新的nettcppbinding
{
TransactionFlow=false,
MaxReceivedMessageSize=20000000,
MaxBufferSize=20000000,
MaxBufferPoolSize=20000000,
ReaderQuotas={MaxNameTableCharCount=20000000},
OpenTimeout=新的时间跨度(0,5,0),
SendTimeout=新的时间跨度(0,5,0),
CloseTimeout=新的时间跨度(0,5,0)
};
tcpBindingPart.Security.Transport.ProtectionLevel=ProtectionLevel.EncryptAndSign;
tcpBindingPart.Security.Transport.ClientCredentialType=TcpClientCredentialType.Windows;
tcpBindingPart.Security.Mode=SecurityMode.None;
var endpointAddressPart=新的EndpointAddress(endPointAddrPart);
this.m_ChannelPartTypes=ChannelFactory.CreateChannel(
tcpBindingPart、endpointAddressPart);
((IContextChannel)m_ChannelPartTypes).OperationTimeout=新的时间跨度(0,5,0);
返回true;
}
捕获(通信对象故障异常故障)
{
//System.Diagnostics.Trace.TraceError(faultEx.ToString());
Console.WriteLine(“收到未知异常。”+faultEx.Message+faultEx.StackTrace);
Console.Read();
返回false;
}
捕获(EndpointNotFoundException endEx)
{
//System.Diagnostics.Trace.TraceError(endEx.ToString());
Console.WriteLine(“收到未知异常。”+endEx.Message+endEx.StackTrace);
Console.Read();
返回false;
}
}
当底层流程花费一分钟以上时,我偶尔会遇到以下错误

信息:

此请求操作已发送到 净。tcp://127.0.0.1:8000/VSMDBCommunication 未在指定时间内收到答复 配置的超时(00:01:00)。这个 分配给此操作的时间可能会缩短 已经是一段较长的历史的一部分 超时。这可能是因为 服务仍在处理 操作,或因为服务已关闭 无法发送回复消息。 请考虑增加 操作超时(通过强制转换 通道/代理到IContextChannel和 设置OperationTimeout属性) 并确保服务能够 连接到客户端


如何以与当前不同的方式强制转换通道以避免此错误,这是有意义的,因为基础请求的计算可能会花费稍多于一分钟的时间。

请尝试设置ReceiveTimeout属性

同时尝试设置ReceiveTimeout属性

将客户端操作超时设置为

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

这将删除您的错误

将客户端操作超时设置为

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

这将删除您的错误

这似乎没有解决问题。这似乎没有解决问题。哪里是客户端,什么是客户端?客户端是服务引用的实例哪里是客户端,什么是客户端?客户端是服务引用的实例