DESKTOP

Communicate Between Two Machines on the Same Network (WCF)

9/26/2010 7:52:12 PM
Use WCF with a TCP/IP binding.

Starting with the result from the previous section, all you need to do is change the configuration information in both the server and the client. In fact, you could just have multiple endpoints on the server and allow clients to connect however they desire.

Here’s the server’s app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="WCFHost.FileService"
behaviorConfiguration="FileServiceMEXBehavior">
<endpoint address=""
binding="netTcpBinding"
contract="FileServiceLib.IFileService"/>
<endpoint address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8080/FileService"/> </baseAddresses>
</host>
</service>

</services>
<behaviors>
<serviceBehaviors>
<behavior name="FileServiceMEXBehavior">
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

The client’s app.config is similarly modified:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="netTcpBinding_IFileService" />
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://remote-pc:8080/FileService"
binding="netTcpBinding"
bindingConfiguration="netTcpBinding_IFileService"
contract="IFileService"
name="netTcpBinding_IFileService"/>
</client>
</system.serviceModel>
</configuration>

Note

To adequately test this on a modern operating system, you may have to create a firewall exception to allow connections to the server.


That’s it. With just a configuration change, the underlying protocol completely changes and you can communicate over the network.

Other  
 
Most View
Xiaomi Phone 2 - High-End Specifications In A Surprisingly Cheap Package (Part 3)
ASP.NET 4 in VB 2010 : ADO.NET Fundamentals (part 6) - Disconnected Data Access
Windows Server 2008 Server Core : Accessing the Windows Package Manager with the PkgMgr Utility, Adding and Removing Applications with the OCSetup Utility
Tablet … Google Nexus 7 By Asus
HTPC Networking Consideration (Part 1) - NAS
SQL Server 2008 : Advanced Stored Procedure Programming and Optimization - Using Cursors in Stored Procedures
Visual Studio 2010 : Managing Extensions with the Extension Manager, Managing Add-Ins with the Add-In Manager
ADO.NET Programming : Microsoft SQL Server CE (part 3) - Retrieving and Displaying Data
Panasonic Lumix DMC-FZ62 - Solid Upgrade Of Last Year's FZ48 Model
Programming Microsoft SQL Server 2005 : The XML Data Type (part 2) - XML Schemas
Top 10
Nikon Coolpix A – An Appealing Camera For Sharp Images (Part 2)
Nikon Coolpix A – An Appealing Camera For Sharp Images (Part 1)
Nikon Coolpix L28 Camera - Ideal Choice For Limited Budgets
Antec GX700 Value Gaming Computer Case
BenQ W703D - Wallet-Friendly Wonder
Canon Pixma Pro-10 A3+ Professional Printer (Part 2)
Canon Pixma Pro-10 A3+ Professional Printer (Part 1)
Dell XPS 12 Convertible Ultrabook Review (Part 3)
Dell XPS 12 Convertible Ultrabook Review (Part 2)
Dell XPS 12 Convertible Ultrabook Review (Part 1)