Chapter 13. Networking
Most interesting computer systems are distributed these days—it’s
increasingly unusual for a program to run in isolation on a single machine.
So .NET provides various ways to communicate across networks. The array of
networking options looks a little bewildering at first: there are 10
namespaces whose names start with System.Net
containing more than 250 classes, and
that’s not even the complete set—there’s an even bigger API for producing
and consuming web services.
Fortunately, it’s simpler than this makes it seem—despite the large API surface area most of the options fall into three categories. There’s WCF—the Windows Communication Foundation, a framework for building and using web services. There are lower-level APIs for working directly with web protocols. Or you can use sockets if you need very low-level control. We’ll start by discussing how to choose the most appropriate style of communication for your application, and then we’ll look at these three options in more detail.
Choosing a Networking Technology
The first step in choosing the right networking API is to decide on the nature of the communication your application requires. There are many different styles of distributed applications. Perhaps you are building a public-facing web service designed to be used by a diverse range of clients. Conversely, you might be writing client code that uses someone else’s web service. Or maybe you’re writing software that runs at both ends of the connection, but even ...
Get Programming C# 4.0, 6th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.