繁体   English   中英

wcf连接超时重试

[英]wcf connection timeout retry

下面是我的WCF连接代码。 如果连接超时我想重试3次。 我怎样才能做到这一点? 谢谢达摩

C#代码

                // Get the status from the client machine
                ServiceReference1.JobsClient Client = new ServiceReference1.JobsClient();
                Client.Endpoint.Address = new System.ServiceModel.EndpointAddress(ConfigurationManager.AppSettings["ServicePath"]);
                FactoryAuditEventNotification.ServiceReference1.ReturnClass SystemStatus_Result;
                SystemStatus_Result = Client.SystemState(System.Environment.MachineName);

                if (SystemStatus_Result.ErrorCode < 0) // Error, set the textbox state
                    this.textBoxState.BeginInvoke((MethodInvoker)(() => this.textBoxState.Text = "Unknown"));
                else
                    this.textBoxState.BeginInvoke((MethodInvoker)(() => this.textBoxState.Text = "Success"));

为什么不使用for循环?

for(int currentCount = 1;currentCount <= 3;currentCount++)
{
    try
    {
    //your connection logic
    }
    catch(EndpointNotFoundException)
    {
    //throw after three retries
    if(currentCount == 3)
        throw;
    }
    catch(Exception)
    {
    //Handle other exceptions as necessary
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM