Skip to content

Instantly share code, notes, and snippets.

@xplicit
Created July 7, 2017 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xplicit/002d99b07513afa07e5f3e36d499e5f2 to your computer and use it in GitHub Desktop.
Save xplicit/002d99b07513afa07e5f3e36d499e5f2 to your computer and use it in GitHub Desktop.
ServerEvents Host
using System.Threading;
using Funq;
using ServiceStack;
public class AppHost : AppSelfHostBase
{
public static ManualResetEvent ShouldQuit = new ManualResetEvent(false);
public AppHost()
: base("SelfHost1", typeof(MyServices).Assembly)
{
}
public override void Configure(Container container)
{
Plugins.Add(new ServerEventsFeature());
}
}
[Route("/stop")]
public class Stop : IReturnVoid
{
}
[Route("/hello/{Name}")]
public class Hello : IReturn<HelloResponse>
{
public string Name { get; set; }
}
public class HelloResponse
{
public string Result { get; set; }
}
public class MyServices : Service
{
public object Any(Hello request) => new HelloResponse { Result = "Hello, {0}!".Fmt(request.Name) };
public void Any(Stop request) => AppHost.ShouldQuit.Set();
}
var host = new AppHost().Init().Start("http://*:9013/");
AppHost.ShouldQuit.WaitOne();
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ServiceStack.Text" version="4.5.12" targetFramework="net45" />
<package id="ServiceStack.Client" version="4.5.12" targetFramework="net45" />
<package id="ServiceStack.Interfaces" version="4.5.12" targetFramework="net45" />
<package id="ServiceStack" version="4.5.12" targetFramework="net45" />
</packages>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment