Created
June 17, 2014 12:29
-
-
Save xanathar/b9e2c02bbc38dbf3d31f to your computer and use it in GitHub Desktop.
HttpListener #2 - WCF / MVC way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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