I Have a Custom WCF Service Host (webServicehost2
) and Factory that is doing some dependency injection (implementing a custom IInstanceProvider
) and also some custom authentication (impementing a custom RequestInterceptor
).
I Have a very small issue in that when i navigate to a REST resource that does not exsist. for example
http://localhost/restservice.svc/
http://localhost/restservice.svc/blah/
I get a 404 Error
, OK that is expected.
What I would like to know is there anyway that I can capture the returning Http error and format it a little nicer.
I'm not sure if there's an easier way, but I did some quick prototyping here, and found that one way to accomplish this is by adding a custom IDispatchMessageInspector implementation that looks at the response message of the service and replaces the content with your own custom HTML page.
It goes basically like this:
I have my sample that does this successfully, but it's way ugly; I'll need to clean it up a bit before posting it.
Here are the relevant code snipets for anyone else attemping this
First an instance of the
IDispatchMessageInspector
Then to inject this into the
IServiceBehaviour
I addedThere may be other code in this that is relevant to my implementation but that is all i added.