Книга: C# 2008 Programmer

The ABCs of WCF

The ABCs of WCF

 Figure 20-17 shows the ABCs of WCF — address, binding, and contract.


Figure 20-17

Address — The address that the service is listening at. This indicates where the service can be located and used. The address for a WCF service is dependent on the communication protocol used.

Binding — The type of binding that you will use to communicate with the service. The binding used determines the security requirements for the communication and how clients will connect to the service.

Contract — The contract defines what the service offers. The following sections discuss each of these points in detail.

Addresses and Endpoints

Every WCF service has an address and endpoints in which it listens for incoming connections. Figure 20-18 shows a WCF service with two endpoints exposed. A client wanting to use the service just needs to send messages to the appropriate endpoint.


Figure 20-18

The address of a WCF service depends on the protocols used for the service. For example, if a WCF service uses the HTTP protocol, then its address may be:

http://<server>:<port>/<service>

https://<server>:<port>/<service>

https://<server>:<port>/<service>.svc

If a WCF service uses TCP as the protocol, its address is in this format:

net.tcp://<server>:<port>/<service>.

For Named Pipes, the address is net.pipe://<server>/<service>.

A service may have an operation that uses any of the protocols (or all). For example, a service may listen at port 80 (endpoint number 1) using HTTP as well as listen at port 5000 (endpoint number 2) using TCP.

Bindings

The bindings of a WCF not only specify the protocols used but also the security requirements for communication. The following table describes the available bindings:

Binding Description
BasicHttpBinding Most basic; limited security and no transactional support. Compatible with traditional ASMX Web Services.
WSHttpBinding More advanced HTTP with WSE security.
WSDualHttpBinding Extends WSHttpBinding and includes duplex communications.
WSFederationHttpBinding Extends WSHttpBinding and includes federation capabilities.
NetTcpBinding Used for TCP communication; supports security, transaction, and so on.
NetNamedPipeBinding Used for named pipe communication; supports security, transaction, and so on.
NetPeerTcpBinding Supports broadcast communication.
MexHttpBinding Publishes the metadata for the WCF service.
NetMsmqBinding Used for MSMQ.
MsmqIntegrationBinding Used for MSMQ.

The bindings of a WCF determine how a client can communicate with the service.

How to use BasicHttpBinding, WSHttpBinding, and NetTcpBinding bindings is shown later in this chapter.

Contracts

Contracts define what a WCF service offers. The types of available contracts are explained in the following table.

Contract Defines
Service All the operations contained in a service.
Operation All the methods, parameters, return types, and so on.
Message How messages are formatted. For instance, data should be included in SOAP header or SOAP message body, and so on.
Fault Faults an operation may return.
Data The type of data used and required by the service.

Оглавление книги


Генерация: 1.816. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз