try
{
Authority authority = new Authority();
System.Net.IWebProxy theProxy = System.Net.WebRequest.DefaultWebProxy;
authority.Proxy = theProxy;
xmlNode = authority.GetUserInfoByNameAndSerialnumber(this.CertName, this.SerialNumber);
authority = null;
}
catch (Exception e)
{
string errorMsg = e.Message;
int count = 3;//三次輸入錯誤則退出
while (count > 0)
{
if (errorMsg.Contains("Proxy"))//如果是因為proxy問題導致exception
{
count--;
try
{
ProxyAuthenticate proxyAuthenticate = new ProxyAuthenticate(WebProxy.GetDefaultProxy().Address.Host);//ProxyAuthenticate為自定義的賬密輸入框
if (proxyAuthenticate.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Authority authority = new Authority();
System.Net.IWebProxy theProxy = System.Net.WebRequest.DefaultWebProxy;
authority.Proxy = theProxy;
authority.Proxy.Credentials = new System.Net.NetworkCredential(proxyAuthenticate.GetUser(), proxyAuthenticate.GetPassword());
xmlNode = authority.GetUserInfoByNameAndSerialnumber(this.CertName, this.SerialNumber);
authority = null;
break;
}
}
catch (Exception ex)
{
errorMsg = ex.Message;
}
}
else
{
throw new Exception(errorMsg);
}
}
}