ServiceStack/ServiceStack — Issue #29: Help: Failing to get AppHostHttpListenerBase working
Author: bluetentacle
Created: 2011-10-14 23:20:25+00:00
State: open

I'm getting back a 404 error back from the host.

Here's the request:

[DataContract]
[RestService("/wildfirecounters/{EngagementType}", "GET")]
public class CounterRequest
{
[DataMember]
public EngagementType EngagementType { get; set; }
}

Here's the response:

[DataContract]
public class CounterResponse
{
public Counter Counter { get; set; }
}

Here's the service:

public sealed class CounterService: RestServiceBase
{
public override object OnGet(CounterRequest request)
{
Counter counter;

if (String.IsNullOrEmpty(request.ResourceUri))
{
counter = CountersServiceProviderGateway.Counters.GetCounters(request.EngagementType);
}
else
{
counter = CountersServiceProviderGateway.Counters.GetCounters(request.EngagementType, request.ResourceUri);
}

return new CounterResponse
{
Counter = counter
};
}

protected override object Run(CounterRequest request)
{
return Get(request);
}
}

Here's the host:

internal sealed class AppHost: AppHostHttpListenerBase
{
///

///	Initializes an instance of the class.
///

public AppHost(): base("CounterViewTestHost", typeof(CounterService).Assembly)
{
}

public override void Configure(Container container)
{
SetConfig(new EndpointHostConfig
{
GlobalResponseHeaders =
{
{ "Access-Control-Allow-Origin", "*" },
{ "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" },
},
WsdlServiceNamespace = "http://www.servicestack.net/types",
LogFactory = new ConsoleLogFactory(),
DebugMode = true,
});
}
}

And here's the unit test that calls it all:

[TestMethod]
public void TestGetThroughHttp()
{
using (var host = new AppHost())
{
var urlBase = "http://localhost:8651/";

host.Start(urlBase);

var client = new JsonServiceClient(urlBase);

var response = client.Get("wildfirecounters/PlayVideo");

Assert.IsTrue(response.Counter.Counts[CounterTimeSpan.Total] > 0);
}
}