FANDOM


Server.csEdit

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.csEdit

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);
            }
        }
    }
}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.