views:

107

answers:

2

We have written a restful service using WCF and are now trying to write FitNesse tests to verify the behaviour of this service.

One test is that a 404 status code is returned if a resource can not be found.

The problem is that we can not find a mechanism for consuming the service that allows us to get the status code of the incomming response. Everything seems to work fine for everything other than 200. We have tried using HttpWebRequest and HttpWebResponse and the WebChannelFactory all of which throw exceptions of various types depending on the HttpStatusCode returned by the service.

Why can't I see the status code???!!

A: 

You can see the status code, in properties of the WebException that is thrown. You can get ex.Status. Then, you can get ex.Response, and access the status code.

John Saunders
A: 

Hi John,

Yes you are right, I was just about to answer my own question!

I think unless I am mistaken you need to cast the Response Property in the WebException to an HttpWebResponse to get the status code.

Thanks Tim

Tim