I have a WebApi application with the following controller:
public class ContentController : ApiController
{
[HttpPost]
public HttpResponseMessage Post(string contentType)
{
return new HttpResponseMessage(HttpStatusCode.OK);
}
}
The route is as follows:
routes.MapHttpRoute("content",
"api/content/{contentType}",
new { controller = "Content", contentType = RouteParameter.Optional });
When I host the service in IIS / cassini, if I send POST to api/content/whatever, then, as expected, my action with the controller is hit.
but
I have a test project that SelfHosts is an api
using (var client = new HttpClient(Server))
{
var result = client.PostAsync(BaseAddress + "api/content/whatever"
var message = result.Content.ReadAsStringAsync().Result;
}
If I debug unit test and go into it result:
{StatusCode: 500, ReasonPhrase: "Internal server error", Version: 1.1, Content: System.Net.Http.ObjectContent`1 [[System.Web.Http.HttpError, System.Web.Http, Version = 5.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35]], Headers: {Content-Type: application / json; encoding = UTF-8}}
Directly, messageliterally simple
An error has occurred
WebApi, , ?
Server - HttpServer , , , :
var httpConfig = new HttpSelfHostConfiguration(BaseAddress);
new ApiServiceConfiguration(httpConfig).Configure();
var server = new HttpSelfHostServer(httpConfig);
server.OpenAsync().Wait();
Server = server;