views:

51

answers:

1

How can I make my client treat 404 Error correctly? Right now it catches a general exception...

My WCF Server uses WebOperationContext.Current.OutgoingResponse.SetStatusAsNotFound(); To return a 404 Error code

however my WCF client interperts it as an EndPointNotFoundException

There was no endpoint listening at http://myUrl that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

The inner exception is WebException "The remote server returned an error: (404) Not Found.

A: 

Here is what I found...


catch (EndpointNotFoundException exception) 
{

                if (exception.InnerException.GetType() == typeof(WebException))
                {
                    WebException webException = (WebException) exception.InnerException;
                    if (webException.Status == WebExceptionStatus.ProtocolError)
                    {
                        if (((HttpWebResponse) webException.Response).StatusCode == HttpStatusCode.NotFound)
                        {
                          ...
                        }

                    }
                }
                else
                {
                    .... 
                }
 }