C# wcf连接超时重试
下面是我的WCF连接代码。如果连接超时,我想重试3次。我该怎么做? 谢谢 达莫 C#代码C# wcf连接超时重试,c#,wcf,C#,Wcf,下面是我的WCF连接代码。如果连接超时,我想重试3次。我该怎么做? 谢谢 达莫 C#代码 // Get the status from the client machine ServiceReference1.JobsClient Client = new ServiceReference1.JobsClient(); Client.Endpoint.Address = new System.Serv
// 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"));
//从客户端计算机获取状态
ServiceReference1.JobsClient客户端=新的ServiceReference1.JobsClient();
Client.Endpoint.Address=new System.ServiceModel.EndpointAddress(ConfigurationManager.AppSettings[“ServicePath]”);
FactoryAuditEventNotification.ServiceReference1.ReturnClass系统状态\u结果;
SystemStatus\u Result=Client.SystemState(System.Environment.MachineName);
如果(SystemStatus\u Result.ErrorCode<0)//错误,则设置文本框状态
this.textBoxState.BeginInvoke((MethodInvoker)(()=>this.textBoxState.Text=“未知”);
其他的
this.textBoxState.BeginInvoke((MethodInvoker)(()=>this.textBoxState.Text=“成功”);
为什么不使用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
}
}
for(int currentCount=1;currentCount