我试图在有/没有 SSL/TLS 或端点的情况下捕获 wcf sercue 的所有异常,如下所示:
try
{
ServiceReference.ServiceClient serviceClient = new ChartLogicServiceClient();
serviceClient.Open();
serviceClient.Login("", "", "");
}
catch (SecurityNegotiationException negotiationException)
{
// Could not establish trust relationship for the SSL/TLS secure channel with authority 'localhost'.
throw;
}
catch (ArgumentException argumentException)
{
// transport wrong config : The provided URI scheme 'https' is invalid; expected 'http'.
//if (argumentException.Message == "The provided URI scheme 'http' is invalid; expected 'https'.\r\nParameter name: via")
throw;
}
catch (MessageSecurityException messageSecurityException)
{
// transport wrong config: The HTTP request was forbidden with client authentication scheme 'Anonymous'.
//- HTTP Request Error
if (messageSecurityException.InnerException.Message == "The remote server returned an error: (403) Forbidden.")
{
throw;
}
else if (messageSecurityException.InnerException.Message == "The remote server returned an error: (404) Forbidden.")
{
throw;
}
}
catch (EndpointNotFoundException endpointNotFoundException)
{
// no endpoint was found or IIS on server was turned off
}
我可以在不调用任何方法的情况下检查 wcf 服务的可用性(我尝试过 Open() 但根本不起作用)?不确定我是否从 WCF 服务中捕获所有异常情况?我的目的是如果客户端在 SSL/TSL 或没有端点时遇到 wcf 异常,我应该运行一个小型实用程序控制台来修复客户端上的 app.config 以映射到 wcf 端点和 . 我真的需要你的建议。谢谢