我试图捕获带/不带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端点和。 我真的需要你的建议。感谢
答案 0 :(得分:0)
您始终可以尝试连接到服务的URL并检查响应代码。也许不是最好的方法,但它应该有效。 e.g。
GET mysite/myservice.svc
并检查HTTP状态代码。