0
我试图抓住WCF sercue所有的异常有/无SSL/TLS或终点,这样的事情:最佳实践
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服务,而无需调用任何方法(我试过打开()但不工作)?不知道我是否从WCF服务中捕获了所有例外情况?我的目的是,如果客户端通过SSL/TSL或无端点获得了wcf异常,我应该运行一个小型的实用程序控制台来修复客户端上的app.config,以便与wcf端点映射。 我真的需要你的建议。谢谢
谢谢,我使用GET WebRequest,WebResponse,它工作正常 –