Important Questions on WCF (Windows Communication Foundation)


Q. What is WCF?

A. Windows Communication Foundation (WCF) is an SDK for developing and deploying services on Windows. WCF provides a runtime environment for services, enabling you to expose CLR types as services, and to consume other services as CLR types. 

WCF is part of .NET 3.0 and requires .NET 2.0, so it can only run on systems that support it.

Q. What is address in WCF and how many types of transport schemas are there in WCF?

A.    Address is a way of letting client know that where a service is located. In WCF, every service is associated with a unique address. This contains the location of the service and transport schemas.

WCF supports following transport schemas 

HTTP (Hyper Text Transfer Protocol)
TCP (Transmission Control Protocol)
Peer network 
IPC (Inter-Process Communication over named pipes) 
MSMQ (Microsoft Message Queuing)

Q. What are contracts in WCF?

A. 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.


Service contracts

Describe which operations the client can perform on the service.
There are two types of Service Contracts.
ServiceContract - This attribute is used to define the Interface.
OperationContract - This attribute is used to define the method inside Interface.


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 we can easily define explicit opt-in data contracts for custom types.

There are two types of Data Contracts.
DataContract - attribute used to define the class
DataMember - attribute used to define the properties.


Q. Where we can host WCF Services?
A. There are three ways of hosting WCF services. 

They are 

1. IIS 
2. Self Hosting 
3. WAS (Windows Activation Service) 

Q. What is binding and how many types are bindings are there in WCF?
A. A binding defines how an endpoint communicates to the world. A binding defines the transport (such as HTTP or TCP) and the encoding being used (such as text or binary). A binding can contain binding elements that specify details like the security mechanisms used to secure messages, or the message pattern used by an endpoint. 

WCF supports nine types of bindings. 

Basic binding 

Offered by the BasicHttpBinding class, this is designed to expose a WCF service as a legacy ASMX web service, so that old clients can work with new services. When used by the client, this binding enables new WCF clients to work with old ASMX services. 

TCP binding 

Offered by the NetTcpBinding class, this uses TCP for cross-machine communication on the intranet. It supports a variety of features, including reliability, transactions, and security, and is optimized for WCF-to-WCF communication. As a result, it requires both the client and the service to use WCF. 


Peer network binding
 

Offered by the NetPeerTcpBinding class, this uses peer networking as a transport. The peer network-enabled client and services all subscribe to the same grid and broadcast messages to it. 


IPC binding 

Offered by the NetNamedPipeBinding class, this uses named pipes as a transport for same-machine communication. It is the most secure binding since it cannot accept calls from outside the machine and it supports a variety of features similar to the TCP binding. 


Web Service (WS) binding 

Offered by the WSHttpBinding class, this uses HTTP or HTTPS for transport, and is designed to offer a variety of features such as reliability, transactions, and security over the Internet. 


Federated WS binding 

Offered by the WSFederationHttpBinding class, this is a specialization of the WS binding, offering support for federated security. 


Duplex WS binding 

Offered by the WSDualHttpBinding class, this is similar to the WS binding except it also supports bidirectional communication from the service to the client. 


MSMQ binding 

Offered by the NetMsmqBinding class, this uses MSMQ for transport and is designed to offer support for disconnected queued calls. 


MSMQ integration binding 

Offered by the MsmqIntegrationBinding class, this converts WCF messages to and from MSMQ messages, and is designed to interoperate with legacy MSMQ clients. 

Q. What is endpoint in WCF?
A. Every service must have Address that defines where the service resides, Contract that defines what the service does and a Binding that defines how to communicate with the service. In WCF the relationship between Address, Contract and Binding is called Endpoint. 

The Endpoint is the fusion of Address, Contract and Binding.

Q. What was the code name of WCF?
A. The code name of WCF was Indigo

WCF is a unification of .NET framework communication technologies which unites the following technologies: - 

NET remoting 
MSMQ 
Web services 
COM+

Q. What are various ways of hosting WCF Service?
A. There are three major ways of hosting a WCF services 

• Self-hosting the service in his own application domain. This we have already covered in the first section. The service comes in to existence when you create the object of Service Host class and the service closes when you call the Close of the Service Host class. 

• Host in application domain or process provided by IIS Server. 

• Host in Application domain and process provided by WAS (Windows Activation Service) Server. 

Q. What is the difference between WCF and Web Services?
A. Web services can only be invoked by HTTP (traditional webservice with .asmx). While WCF Service or a WCF component can be invoked by any protocol (like http, tcp etc.) and any transport type. 

Second web services are not flexible. However, WCF Services are flexible. If you make a new version of the service then you need to just expose a new end. Therefore, services are agile and which is a very practical approach looking at the current business trends. 

We develop WCF as contracts, interface, operations, and data contracts. As the developer we are more focused on the business logic services and need not worry about channel stack. WCF is a unified programming API for any kind of services so we create the service and use configuration information to set up the communication mechanism like HTTP/TCP/MSMQ etc 

Q. What is three major points in WCF?
A. We Should remembers ABC. 

Address --- Specifies the location of the service which will be like http://Myserver/MyService.Clients will use this location to communicate with our service. 

Binding --- Specifies how the two pares will communicate in term of transport and encoding and protocols 

Contract --- Specifies the interface between client and the server. It’s a simple interface with some attribute.

Q. What are the various ways of hosting WCF service?
A. Self hosting the service in his own application domain. This we have already covered in the first section. The service comes in to existence when you create the object of Service Host class and the service closes when you call the Close of the Service Host class. 
Host in application domain or process provided by IIS Server. 
Host in Application domain and process provided by WAS (Windows Activation Service) Server.

Q. Difference between WCF and WebServies?
A.

Web Services 

1.It can be accessed only over HTTP 
2.It works in stateless environment 

WCF 

WCF is flexible because its services can be hosted in different types of applications. The following lists several common scenarios for hosting WCF services: 
IIS 
WAS 
Self-hosting 
Managed Windows Service

Q. What is SOA service?
A. SOA is Service Oriented Architecture. SOA service is the encapsulation of a high level business concept. A SOA service is composed of three parts. 
1. A service class implementing the service to be provided. 
2. An environment to host the service. 
3. One or more endpoints to which clients will connect.

Q. What is .svc file in WCF?
A. .svc file is a .txt file. This is similar to .asmx file in web services. 

This file contains the details required for WCF service to run it successfully. 

This file contains following details: 
1. Language (C# / VB) 
2. Name of the service 
3. Where the service code resides 

Comments