Simplest method to build a client-server in C# over WCF

Yaroslav Menshikov
2 min readOct 16, 2020

Let’s create a simple console application.

1. Creating an interface for transferring objects between our client and server.

We added two methods for calculating the sum and multiplication of two given numbers.

2. Creating a class based on our interface.

3. Add variables to the main class and fill it with your data.

serviceAddress — where our server will listen for new connections

serviceName — the name of our service

note: ‘127.0.0.1’ is a local Ip of any computer, ‘10000’ — you can choose any free port in your system

Creating a server part.

We should create a service host, add a service endpoint for the host, and open it.

note: you can choose the type of your server binding: NetTcpBinding or NetHttpBinding. I choose the first one because I don’t want to depend on HTTP Windows settings like system proxy.

Creating a client part:

We have to create a connection using the same server address.

From now on we can access a server and call the created methods:

Here is all the code of the main class:

4. Run this code and see the result of the program.

2+3 = 5

5*4 = 20

You see, everything is simple )

--

--