Skip to content

Instantly share code, notes, and snippets.

@JayDouglass
Created June 1, 2011 04:35
Show Gist options
  • Save JayDouglass/1001794 to your computer and use it in GitHub Desktop.
Save JayDouglass/1001794 to your computer and use it in GitHub Desktop.
WCF REST service host from console
using System.Diagnostics;
using System.ServiceModel.Web;
using System.ServiceModel.Description;
namespace WCFRest.ConsoleServiceHost
{
class Program
{
static void Main(string[] args)
{
using (var host = new ServiceHost(typeof(ServiceImpl),
new Uri(@"http://localhost:9000/ServiceAddress")))
{
host.AddServiceEndpoint(typeof(IServiceInterface),
new WebHttpBinding(WebHttpSecurityMode.None),
String.Empty)
.Behaviors.Add(new WebHttpBehavior());
host.Open();
System.Console.WriteLine("Press <ENTER> to terminate the service host");
System.Console.ReadLine();
}
}
}
}
@JayDouglass
Copy link
Author

Using WebServiceHost will take care of adding the WebHttpBehavior. WebServiceHostFactory should be used in .svc files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment