The HttpClient Object and REST Service URLs

I'm working on a project that involves a custom upload application page with a call to a validation web service. I've implemented the calls with the HttpClient object, used the nifty async/await C# features for asynchronous communication, which is just dandy, and called the HttpClient.PostAsync() method and processed some results (as you do).

For the longest time (I swear, it's been a few days), the service would return 404, which, why? I'd tried all sorts of things: switching to a GET request to test communications, messing with tracing and logging on the service side, and generally freaking out about my inability to make a simple REST service call. I used the Advanced REST Client app for Chrome on local machines, dev VMs, machines on other networks and domains, all sorts of things.

And then, it hit me. (Spoiler alert, missing trailing slash.)

The HttpClient object has a member for BaseAddress, where you'd put the URL of the root of the service, and then the various method calls (e.g., PostAsync) take a relative path to create the full, absolute URL. The BaseAddress member is even a System.Uri object, not even a string! Anyway, it turns out that the lack of a trailing slash means that the final "directory" in the BaseAddress gets run right up against the first part of the request URI, which was, in fact, causing a 404.

As Timothy Shields mentions in this Stack Overflow question:

You must place a slash at the end of the BaseAddress, and you must not place a slash at the beginning of your relative URI

Completely not what I expected, but now I know.