Server.cs[]
Server process:
using System; using System.ServiceModel; namespace WCFHelloServer { [ServiceContract] public interface IHelloGreeting { [OperationContract] string Hello(string name); } [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] class HelloGreeting : IHelloGreeting { public string Hello(string name) { Console.WriteLine("SERVER - Processing Ping('{0}')", name); return "Hello, " + name; } } class Server { public static void Main() { using (var svh = new ServiceHost(typeof(HelloGreeting))) { // svh.AddServiceEndpoint(typeof(IHelloGreeting), new NetTcpBinding(), "net.tcp://localhost:8000"); svh.AddServiceEndpoint(typeof(IHelloGreeting), new NetNamedPipeBinding(NetNamedPipeSecurityMode.None), "net.pipe://localhost/WCFHelloServer/HelloGreeting"); svh.Open(); Console.WriteLine("SERVER - Running... Press <Enter> to quit"); Console.ReadLine(); } } } }
Client.cs[]
Client process:
using System; using System.ServiceModel; using WCFHelloServer; namespace WCFHelloClient { class Client { static void Main() { // using (var scf = new ChannelFactory<IHelloGreeting>(new NetTcpBinding(), "net.tcp://localhost:8000")) using (var scf = new ChannelFactory<IHelloGreeting>(new NetNamedPipeBinding(NetNamedPipeSecurityMode.None), "net.pipe://localhost/WCFHelloServer/HelloGreeting")) { Console.Write("CLIENT - What's your name?: "); var name = Console.ReadLine(); var s = scf.CreateChannel(); var response = s.Hello(name); Console.WriteLine("CLIENT - Response from service: {0}", response); } } } }