Skip to content

Instantly share code, notes, and snippets.

@xanathar
Created June 17, 2014 12:29
Show Gist options
  • Save xanathar/b9e2c02bbc38dbf3d31f to your computer and use it in GitHub Desktop.
Save xanathar/b9e2c02bbc38dbf3d31f to your computer and use it in GitHub Desktop.
HttpListener #2 - WCF / MVC way
public class CommandsController : ApiController
{
[HttpGet][HttpPost][HttpDelete]
public void Action1()
{
}
[HttpGet]
[HttpPost]
[HttpDelete]
public void Action2(string file)
{
}
}
class MessageServer
{
HttpSelfHostConfiguration config;
HttpSelfHostServer server;
public MessageServer(string baseAddress)
{
config = new HttpSelfHostConfiguration(baseAddress);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{action}/{file}",
defaults: new { file = RouteParameter.Optional }
);
server = new HttpSelfHostServer(config);
// Start listening
server.OpenAsync().Wait();
//Debug.WriteLine("Listening on " + _baseAddress);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment