I have a wcf rest service on IIS 7.5. When someone visits a part of the endpoint that doesn't exist (i.e. http://localhost/rest.svc/DOESNOTEXIST vs http://localhost/EXISTS) they are presented with a Generic WCF gray and blue error page with status code 404. However, I would like to return something like the following:
<service-response>
<error>The url requested does not exist</error>
</service-response>
I tried configuring the custom errors in IIS, but they only work if requesting a page outside of the rest service (i.e. http://localhost/DOESNOTEXIST).
Does anyone know how to do this?
Edit After the answer below I was able to figure out I needed to create a WebHttpExceptionBehaviorElement class that implements BehaviorExtensionElement.
public class WebHttpExceptionBehaviorElement : BehaviorExtensionElement
{
///
/// Get the type of behavior to attach to the endpoint
///
public override Type BehaviorType
{
get
{
return typeof(WebHttpExceptionBehavior);
}
}
///
/// Create the custom behavior
///
protected override object CreateBehavior()
{
return new WebHttpExceptionBehavior();
}
}
I was then able to reference it in my web.config file via:
<extensions>
<behaviorExtensions>
<add name="customError" type="Service.WebHttpExceptionBehaviorElement, Service"/>
</behaviorExtensions>
</extensions>
And then adding
<customError />
to my default endpoint behaviors.
Thanks,
Jeffrey Kevin Pry