Created
December 7, 2016 20:03
-
-
Save deostroll/23295ce999cd4ddc882fcd4c48c3a385 to your computer and use it in GitHub Desktop.
wcf console hoster
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
// 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