In WCF, every service is associated with a unique address. The address provides two important elements: the location of the service, and the transport protocol, or transport schema, used to communicate with the service. The location portion of the address indicates the name of the target machine, site, or network; a communication port, pipe, or queue; and an optional specific path, or URI (Universal Resource Identifier). A URI can be any unique string, such as the service name or a globally unique identifier (GUID).
WCF supports the following transport schemas:
HTTP
TCP
Peer network
IPC (Inter-Process Communication)
MSMQ
Addresses always have the following format:
[base address]/[optional URI]
The base address is always in this format:
[transport]://[machine or domain][:optional port]
Here are a few sample addresses:
http://localhost:8001 http://localhost:8001/MyService net.tcp://localhost:8002/MyService net.pipe://localhost/MyPipe net.msmq://localhost/private/MyQueue net.msmq://localhost/MyQueue
The way to read an address such as this:
http://localhost:8001
is like this: "Using HTTP, go to the machine called localhost
, where on port 8001 someone is waiting for my calls."
If there is also a URI, as in:
http://localhost:8001/MyService
the address will read as follows: "Using HTTP, go to the machine called localhost
, where on port 8001 someone called MyService
is waiting for my calls."
TCP addresses use net.tcp
for transport and
typically include a port number, as in:
net.tcp://localhost:8002
/MyService
When a port number is not specified, the TCP address defaults to port 808:
net.tcp://localhost/MyService
It is possible for two TCP addresses (from the same host, as discussed later in this chapter) to share a port:
net.tcp://localhost:8002
/MyService net.tcp://localhost:8002
/MyOtherService
TCP-based addresses are used throughout this book.
Tip
You can configure TCP-based addresses from different service hosts to share a port.
HTTP addresses use http
for transport, and can also
use https
for secure transport. You typically use HTTP
addresses with outward-facing Internet-based services, and you can specify a port as shown
here:
http://localhost:8001
When the port number is unspecified, it defaults to 80 (and port 443 for HTTPS). As with TCP addresses, two HTTP addresses from the same host can share a port, even on the same machine.
HTTP-based addresses are also used throughout this book.
IPC addresses use net.pipe
for transport, to
indicate the use of the Windows named pipe mechanism. In WCF, services that use IPC can
only accept calls from the same machine. Consequently, you must specify either the
explicit local machine name or localhost
for the
machine name, followed by a unique string for the pipe name:
net.pipe://localhost/MyPipe
You can open a named pipe only once per machine, so it is not possible for two named pipe addresses to share a pipe name on the same machine.
IPC-based addresses are used throughout this book.
Tip
The IPC address format is incorrect, indicating the mechanism instead of the
protocol. The correct schema format should have been net.ipc
instead of net.pipe
, much like
the TCP address uses net.tcp
rather than net.socket
.
MSMQ addresses use net.msmq
for transport, to
indicate the use of the Microsoft Message Queue (MSMQ). You must specify the queue name.
When you're dealing with private queues you must also specify the queue type, but that can
be omitted for public queues:
net.msmq://localhost/private/MyService net.msmq://localhost/MyService
Chapter 9 is dedicated to making queued calls.
Peer network addresses use net.p2p
for transport,
to indicate the use of the Windows peer network transport. You must specify the peer
network name as well as a unique path and port. Using and configuring peer networks is
beyond the scope of this book, and you will see very little mention of peer networks in
subsequent chapters. In most cases, a desire to use a peer network actually indicates a
need for the publish-subscribe pattern. Appendix C
presents my helper framework for this pattern.
Get Programming WCF Services, 2nd 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.