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 scheme, 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 schemes:
HTTP/HTTPS
TCP
IPC
Peer network
MSMQ
Service bus
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:
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.
Note
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
If you do not specify the port number, 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 (Inter-Process Communication) 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.
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 you can omit that for public queues:
net.msmq://localhost/private/MyService net.msmq://localhost/MyService
Chapter 9 is dedicated to making queued calls.
Windows Azure AppFabric Service Bus addresses use sb
, http
,
or https
for transport, and must
include the service bus address along with the service namespace, for
example:
sb://MyNamespace.servicebus.windows.net/
Chapter 11 covers the service bus in depth.
Get Programming WCF Services, 3rd 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.