在使用/不使用SSL/TLS的客户端上验证wcf端点的最佳实践



我试图捕获带有/不带有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'.rnParameter 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端点和。我真的需要你的建议。感谢

您可以随时尝试连接到服务的URL并检查响应代码。也许不是最好的方法,但它应该有效。例如

GET mysite/myservice.svc

并检查HTTP状态代码。

相关内容

  • 没有找到相关文章

最新更新