Question

I tried to catch all exception of wcf sercue with/without SSL/TLS or endpoint, something like this:

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

        }

Can i check the available of wcf service without calling any method ( i tried Open() but not work at all)? Not sure i catch all cases of exception from WCF service? My purpose is if client got wcf exception with SSL/TSL or no endpoint, i should run a small utility console to fix app.config on client to map with wcf endpoint and . I really need your suggestions. Thanks

Was it helpful?

Solution

You can always try to connect to the URL of the service and check the response code. Maybe not the best way, but it should work. e.g.

GET mysite/myservice.svc

and check for the HTTP status code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top