Configuring a TCP-Based Binding

At this point, the host and client applications are both configured to use the simplest of the HTTP-based
bindings, basicHttpBinding. Recall that the benefit of offloading settings to configuration files is that you
can change the underlying plumbing in a declarative manner and expose multiple bindings for the same
service.
To illustrate this, you can try a little experiment. Create a new folder on your C: drive (or wherever
you happen to be saving your code) named EightBallTCP; in this new folder, create two subdirectories
named Host and Client.
Next, use Windows Explorer to navigate to the \bin\Debug folder of the host project and copy
MagicEightBallServiceHost.exe, MagicEightBallServiceHost.exe.config, and
MagicEightBallServiceLib.dll to the C:\EightBallTCP\Host folder. Now use a simple text editor to open
the *.config file for editing and modify the existing contents as follows:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="MagicEightBallServiceLib.MagicEightBallService">
<endpoint address =""
binding="netTcpBinding"
contract="MagicEightBallServiceLib.IEightBall"/>
<host>
<baseAddresses>
<add baseAddress ="net.tcp://localhost:8090/MagicEightBallService"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Essentially, this host’s *.config file strips out all the MEX settings (because you already built the
proxy) and establishes that it is using the netTcpBinding binding type through a unique port. Now run
the application by double-clicking the *.exe. If all is well, you should see the host output shown here:
***** Console Based WCF Host *****
***** Host Info *****
Address: net.tcp://localhost:8090/MagicEightBallService
Binding: NetTcpBinding
Contract: IEightBall
**********************
The service is ready.
Press the Enter key to terminate service.
To complete the test, copy the MagicEightBallServiceClient.exe and
MagicEightBallServiceClient.exe.config files from the \bin\Debug folder of the client application into
the C:\EightBallTCP\Client folder. Update the client configuration file like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<client>
<endpoint address="net.tcp://localhost:8090/MagicEightBallService"
binding="netTcpBinding"
contract="ServiceReference1.IEightBall"
name="netTcpBinding_IEightBall" />
</client>
</system.serviceModel>
</configuration>
This client-side configuration file is a massive simplification compared to what the Visual Studio
proxy generator authored. Notice how you have completely removed the existing <bindings> element.
Originally, the *.config file contained a <bindings> element with a <basicHttpBinding> sub-element that
supplied numerous details of the client’s binding settings (e.g., timeouts).
The truth is you never needed that detail for this example because you automatically obtain the
default values of the underlying BasicHttpBinding object. If you needed to, you could of course update
the existing <bindings> element to define details of the <netTcpBinding> sub-element; however, doing so
is not required if you are happy with the default values of the NetTcpBinding object.
In any case, you should now be able to run your client application. Assuming the host is still running
in the background, you will be able to move data between your assemblies using TCP.