Skip to content

Instantly share code, notes, and snippets.

@deostroll
Created December 7, 2016 20:03
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 deostroll/23295ce999cd4ddc882fcd4c48c3a385 to your computer and use it in GitHub Desktop.
Save deostroll/23295ce999cd4ddc882fcd4c48c3a385 to your computer and use it in GitHub Desktop.
wcf console hoster
// add reference to system.dll system.servicemodel.dll during compilation
using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Collections.Generic;
namespace WcfConsoleApp
{
[ServiceContract]
public interface IService
{
[OperationContract]
void EchoList (List<int> numbers);
}
class MainClass
{
public static void Main (string[] args)
{
// Console.WriteLine ("Hello World!");
try {
var url = new Uri("http://localhost:3001/myservice");
var host = new ServiceHost (typeof(Service), url);
host.AddServiceEndpoint (typeof(IService),
new BasicHttpBinding (), "");
var behavior = new ServiceMetadataBehavior ();
var debug = new ServiceDebugBehavior();
debug.HttpHelpPageEnabled = true;
debug.IncludeExceptionDetailInFaults=true;
behavior.HttpGetEnabled = true;
host.Description.Behaviors.Add (behavior);
// host.Description.Behaviors.Add(debug);
host.Open ();
// host.Faulted+= (object sender, EventArgs e) => {
// Console.WriteLine(e.GetType().Name);
// };
Console.WriteLine ("Service is running @ {0}", url);
Console.ReadLine();
host.Close();
} catch (Exception ex) {
throw;
}
}
}
public class Service : IService
{
public Service ()
{
}
public void EchoList(List<int> numbers)
{
Console.WriteLine ("{0} : {1}", DateTime.Now.ToLongTimeString (), string.Join (", ", numbers));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment