Craig, this is what I have that your code looks like and that should be fine:
class Program
{
static void Main(string[] args)
{
var baseAddress = "http://localhost:8080/";
HttpSelfHostServer server = null;
try
{
var config = new HttpSelfHostConfiguration(baseAddress);
config.Routes.MapHttpRoute(
name: "default",
routeTemplate: "api/{controller}/{id}",
defaults: new { controller = "Home", id = RouteParameter.Optional });
server = new HttpSelfHostServer(config);
server.OpenAsync().Wait();
Console.WriteLine("Hit ENTER to exit");
Console.ReadLine();
}
finally
{
if (server != null)
{
server.CloseAsync().Wait();
}
}
}
}
public class HomeController : ApiController
{
public string Get()
{
return "Hello World";
}
}
If this doesn't work then something strange is going on. One thing to try is turning on exceptions and run it in debug (see under the Debug/Exceptions menu and then check "CLR exceptions"). That should give you what the exception is.
Henrik Fryst...
Member
96 Points
13 Posts
Microsoft
Re: 500 Errors
Feb 20, 2012 04:37 AM|LINK
Craig, this is what I have that your code looks like and that should be fine:
class Program { static void Main(string[] args) { var baseAddress = "http://localhost:8080/"; HttpSelfHostServer server = null; try { var config = new HttpSelfHostConfiguration(baseAddress); config.Routes.MapHttpRoute( name: "default", routeTemplate: "api/{controller}/{id}", defaults: new { controller = "Home", id = RouteParameter.Optional }); server = new HttpSelfHostServer(config); server.OpenAsync().Wait(); Console.WriteLine("Hit ENTER to exit"); Console.ReadLine(); } finally { if (server != null) { server.CloseAsync().Wait(); } } } } public class HomeController : ApiController { public string Get() { return "Hello World"; } }If this doesn't work then something strange is going on. One thing to try is turning on exceptions and run it in debug (see under the Debug/Exceptions menu and then check "CLR exceptions"). That should give you what the exception is.
Thanks,
Henrik