I found this great article that tells you how to do testing for WCF services exposed as web services, especially REST services (like the ones we create in my company for the project I work on now).
What’s the problem ?
Typically, for HTTP GET services, you can just put a URL that matches the URI template of the service (the template of the URLs that call the service) in the browser, and simply see what comes back in the browser itself
However, when you want to test a service with other HTTP verbs than GET (Say POST, PUT), you need a console that creates the HTTP request with headers and request body and such, because a browser normally has no way of making you create a new customized request (because it creates them for you and encapsulates the entire process of request/response).
Usually you write that console on your own. We wrote one for the current project but it didn’t serve all our needs.
There’s a program called “Fiddler” (Microsoft Freeware). This program works as proxy server that allows you to intercept and inspect requests and responses for all the web calls you do from your machine. This is very useful but as Firefox extensions do this for us, I haven’t personally installed it for a while.
However, Fiddler has a great feature called “Request Builder”. This is where you can construct your request with all parameters and such and change any part of it (headers, body, raw request) and see the response in multiple views (Raw, Text XML, …).
You can put the URL of your service in it, choose (or type) the HTTP verb and HTTP protocol version (by default 1.1) it uses, and then check the result to see whether it is what you expect or what.
Notes on usage
- With Vista or IPv6 supported OS, this fails sometimes especially when your service is hosted with ASP.NET development server (that’s included in Visual Studio). To fix that in Fiddler, go to Tools->Fiddler Options and then uncheck “Enable IPv6 (If available)”.
- This is how Fiddler looks like in sample test
- The part to the left is the previous HTTP connections. You can fill the request builder parameter by dragging any of them.
- The “Content-Length” header is filled with the right value automatically for you by Fiddler itself.
- Click “Manual proxy configuration”
- Enter 127.0.0.1 in “HTTP Proxy” (and “SSL Proxy” if you want this for HTTPS) and then “8888” (default port for fiddler, can be changed from it) in the “Port”.
- Clear the “No Proxy for” textbox to be able to test URLs on “localhost”.
You can alternatively keep it and use http://MachineName instead of http://localhost when testing.
The One Resource for This
This is coming from a great article that talks about the topic (but not with all the notes). The article also shows a VERY NICE example of creating a REST web services WCF project to be hosted in IIS.
How did I learn that?
As a bonus for coming here, I'm giving away a free newsletter for web developers that you can sign up for from here.
It's not an anything-and-everything link list. It's thoughtfully collected picks of articles and tools, that focus on Angular 2+, ASP.NET (4.x/MVC5 and Core), and other fullstack developer goodies.
Take it for a test ride, and you may unsubscribe any time.
You might also want to support me by checking these out [Thanks]: