Data | The type of data used and required by the service. |
Messaging Patterns
Traditional ASMX Web Services use the request/response communication model. This model has some disadvantages. In some cases, the client might want to call the service without waiting for a response from the service. For example, you might want to call a service rapidly to turn on and off a switch and you do not need a response from the service. Using the request/response model, all requests made by the client have to wait for a reply from the service (even if the request does not return a result). The result is unnecessary blocking on the client side, especially if there are many queued requests on the service's end.
WCF supports three communication models (also known as
□ Request/response
□ One-way (simplex)
□ Two-way (duplex)
The one-way messaging pattern allows clients to fire off a request and forget about it; no response is needed from the service. The two-way messaging pattern allows both the service and the client to send and receive messages.
Hosting Web Services
As mentioned earlier, WCF services can be hosted using different forms:
□ Web Servers — IIS; similar to Web Services
□ Executable — Console application, Windows Forms, WPF, and so on
□ Windows Service — Runs in the background
□ Windows Activation Service (WAS) — Simpler version of IIS
In the earlier example, the WCF service is hosted by the WCF Service Host (see Figure 20-19), a utility provided by Visual Studio 2008.

Figure 20-19
If you host a WCF service using an executable or Windows service, that WCF service is said to be self- hosted.
Building WCF Services
This section explores more sophisticated WCF services that illustrate the various theories presented earlier. Let's start off with creating a WCF that exposes multiple endpoints.
Exposing Multiple Endpoints
A WCF service can expose multiple endpoints. Follow along to build a WCF service that exposes endpoints using two different bindings: WSHttpBinding
and BasicHttpBinding
.
Using Visual Studio 2008, create a new WCF Service Application and name it MultipleEndpointsService
(see Figure 20-20).

Figure 20-20
In this example, the WCF service is hosted by the ASP.NET Development Server, a web server shipped with Visual Studio 2008. Because the service is hosted by a web server, the NetTcpBinding
binding is not supported.
Edit the Web.config
file by right-clicking it in Solution Explorer and selecting Edit WCF Configuration. (You can also launch the WCF Service Configuration Editor by selecting Tools→WCF Service Configuration Editor.)
Expand the Endpoints node, and select the first endpoint. Name it WS (see Figure 20-21).

Figure 20-21
Right-click on the Endpoints node, and select New Service Endpoint to add a new endpoint to the service (see Figure 20-22).

Figure 20-22
Name the new endpoint BASIC, and set its various properties as indicated (see Figure 20-23).

Figure 20-23
Property | Value |
---|---|
Address | asmx |
Binding | basicHttpBinding |
Contract | MultipleEndpointsService.IService1 |
Save and close the Web.config
file. Build the MultipleEndpointsService