Introduction to WCF Concepts - Services
(Page 4 of 4 )
WCF applications expose functionality through services. A service is a Common Language Runtime (CLR) type that encapsulates business functionality and exposes a set of methods that can be accessed by remote clients. In order for a regular CLR type to be considered a service it must implement a service contract.
A service contract is defined by applying theServiceContractAttributeto a class or interface. When applied to a class, the class becomes a service type. When applied to an interface, any class that implements the interface becomes a service type. In either case, methods exposed by the class or interface must be decorated with theOperationContractAttributeto be considered part of the service contract. Methods with this attribute are considered service operations.
A service type must be hosted before clients can invoke service operations.
Hosting
Service functionality is made available at runtime through a host process--any managed process will do the trick. Many hosting options are available for WCF services, including:
Self-hosting
This includes console applications, Windows Forms or
WPF applications, or Windows services.
Internet Information Services (IIS)
Services can be hosted alongside other ASP.NET
applications, for example.
Windows Activation Service (WAS)
This is similar to IIS hosting but is only available to
IIS 7.0.
Each hosting environment has its benefits and appropriate uses, which will be discussed in Chapter4.
Although a host process is important, ultimately it is the service model that knows how to process messages targeting a service. For this aServiceHostinstance is associated with each service type.ServiceHostis part of the service model and is responsible for initializing communication channels that receive messages to a service. Basically, to host any service, you construct aServiceHost, provide it with a service type to activate for incoming messages, provide it with one or more addresses where the service can be located along with the service contract supported by each address, and provide it with the supported communication protocols.
You can think of theServiceHost as responsible for managing the lifetime of the communication channels for the service.
Endpoints
When the ServiceHost opens a communication channel for a service, it must expose at least one endpoint for the service so that clients can invoke operations. In fact, endpoints are the key to invoking service functionality. An endpoint describes where services can be reached, how they can be reached, and what operations can be reached. Thus, endpoints have three key parts:
Address
Refers to the URI where messages can be sent to the
service.
Binding
Bindings indicate the protocols supported when
messages are sent to a particular address.
Contract
Each address supports a specific set of operations,
as described by a service contract.
TheServiceHost is provided with a list of endpoints before the communication channel is opened. These endpoints each receive messages for their associated operations over the specified protocols.
Please check back next week for the continuation of this article.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
|
This article is excerpted from chapter 1 of the book Learning WCF A Hands-on Guide, written by Michele Leroux Bustamante (O'Reilly, 2007; ISBN: 0596101627). Check it out today at your favorite bookstore. Buy this book now.
|
|