WCF Presentation
WCF Presentation
WCF Presentation
The second generation started in mid 1990s and marks the introduction of OS
with GUI and this demanded for developing software with extensive reusability.
It introduced new concepts like :
- Location transperance
- Tight coupling etc.
The third generation is called internet era started in the early 2000s. It aimed at
developing distributed applications. It took the software development towards a
service oriented direction.
Introduction of Remoting
When a client calls the remote method, the proxy receives the call, encodes the
message using an appropriate formatter, then sends the call over the channel to
the server process. A listening channel on the server appdomain picks up the
request and forwards it to the server remoting system, which locates and
invokes the methods on the requested object. Once the execution is completed,
the process is reversed and the results are returned back to the client.
Web services serialize objects through XML contained in the SOAP messages
and can thus only handle items that can be fully expressed in XML
Introduction of WCF
When client apps, which are going to use your service, may be written
in Java or .Net.
Advantages of WCF
Known Advantages:
Makes UI programming & distributed programming very easy.
What is SOA
SOA is the practice of sequestering the core business functions into independent
services that dont change frequently. These services are glorified functions that are
called by one or more presentation programs. The presentation programs are volatile
bits of software that present data to, and accept data from, various users.
SOA is nothing more than separating changeable elements from unchangeable
elements.
1. Services in WCF
Description
The WCF applications expose the functionality through services. A Service is a Common Language
Runtime(CLR) type that encapsulate business functionality and exposes a set of methods that
can be accessed by remote clients.
A service contract is defined by applying the ServiceContractAttribute to 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 the OperationContractAttribute to 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.
2. Addresses
Description:
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.
a) TCP Addresses
Ex. net.tcp://localhost:8002/MyService.
b) HTTP Addresses
Ex. http://localhost:8001
c) IPC Addresses
Ex. net.pipe://localhost/MyPipe
d) MSMQ Addresses
Ex. net.msmq://localhost/MyService
3. Contracts
Description:
In WCF, all services expose contracts. The contract is a platform-neutral and standard
way of describing what the service does. WCF defines four types of contracts.
a) Service Contracts
Describe which operations the client can perform on the service.
b) Data Contracts
Define which data types are passed to and from the service. WCF defines implicit
contracts for built-in types such as int and string, but you can easily define explicit optin data contracts for custom types
c) Fault Contracts
Define which errors are raised by the service, and how the service handles and
propagates errors to its clients
d) Message Contracts
Allow the service to interact directly with messages. Message contracts can be typed or
untyped, and are useful in interoperability cases and when there is an existing message
format you have to comply with.
4. Hosting
Description:
Every WCF service must be hosted in a Windows process called the host process. A
single host process can host multiple services, and the same service type can be
hosted in multiple host processes. The host can be provided by IIS, by the Widows
Activation Service (WAS) on Windows Vista, or by the developer as part of the
application.
So each .NET host process can have many app domains. Each app domain can have
zero or more service host instances. However, each service host instance is dedicated
to a particular service type. When you create a host instance, you are in effect
registering that service host instance with all the endpoints for that type on the host
machine that correspond to its base addresses. Each service host instance has zero or
more contexts.
a) IIS Hosting
Hosting in IIS is very similar to hosting a classic ASMX web service. You need to create
a virtual directory under IIS and supply a .svc file. The .svc file functions similar to an
.asmx file, and is used to identify the service code behind the file and class.
b) Using VS 2005
You can use Visual Studio 2005 to generate a boilerplate IIS-hosted service. From the
File menu, select New Website and then select WCF Service from the New Web Site
dialog box. This causes Visual Studio 2005 to create a new web site, service code, and
matching .svc file. You can also use the Add New Item dialog to add another service
later on.
c) Web.Config file
The web site config file (Web.Config) must list the types you want to expose as
services. You need to use fully qualified type names, including the assembly name.
<system.serviceModel> <services> <service name = "MyNamespace.MyService"> ...
</service> </services> </system.serviceModel>
d) Self Hosting
Self-hosting is the name for the technique used when the developer is responsible for
providing and managing the life cycle of the host process. Self-hosting is used both in
the case of wanting a process (or machine) boundary between the client and the
service, and when using the service in-procthat is, in the same process as the client.
5. Bindings
Description
WCF groups together a set of communication aspects in bindings. A binding is
merely a consistent, canned set of choices regarding the transport protocol,
message encoding, communication pattern, reliability, security, transaction
propagation, and interoperability. You can use the WCF-provided bindings as is, you
can tweak their properties, or you can write your own custom bindings from scratch.
A single service can support multiple bindings on separate addresses.
a)
Standard Bindings
WCF defines nine standard bindings:
Basic Binding
TCP Binding
P2P Binding
IPC Binding
WS Binding
Federated WS Binding
Duplex WS Binding
MSMQ Binding
6. End Points
Every service is associated with an address that defines where the service is, a
binding that defines how to communicate with the service, and a contract that
defines what the service does. The endpoint is the fusion of the address,
contract, and binding (ABC)
Contract:- the contract is the actual interface that the service implements.
Every endpoint must have all three elements, and the host exposes the endpoint.
Logically
Every service must expose at least one business endpoint and each endpoint
has exactly one contract. All endpoints on a service have unique addresses, and
a single service can expose multiple endpoints. These endpoints can use the
same or different bindings and can expose the same or different contracts. There
is absolutely no relationship between the various endpoints a service provides.
Sample
WCF
Thank you