WCF 4 Interview Questions and Answers

WCF 4 Interview Questions with Answers

WCF 4 -Windows Communication Foundataion interview questions are very important as wcf is widely used in almost all web applications today.Lets discuss some important WCF interview questions. This also includes basic as well as advanced interview questions on WCF 4.

1.What is WCF?
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. WCF is Microsoft’s unified programming model for building service-oriented applications with managed code. It extends the .NET Framework to enable developers to build secure and reliable transacted Web services that integrate across platforms and interoperate with existing investments.

Windows Communication Foundation combines and extends the capabilities of existing Microsoft distributed systems technologies, including Enterprise Services, System.Messaging, Microsoft .NET Remoting, ASMX, and WSE to deliver a unified development experience across multiple axes, including distance (cross-process, cross-machine, cross-subnet, cross-intranet, cross-Internet), topologies (farms, fire-walled, content-routed, dynamic), hosts (ASP.NET, EXE, Windows Presentation Foundation, Windows Forms, NT Service, COM+), protocols (TCP, HTTP, cross-process, custom), and security models (SAML, Kerberos, X509, username/password, custom).

2.What are types of  contracts in WCF?
WCF defines four types of contracts.
1. Service contracts : Describe which operations the client can perform on the service.

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

3. Fault contracts : Define which errors are raised by the service, and how the service handles and propagates errors to its clients.

4. 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 we have to comply with

3.What are different isolation levels provided in WCF?
The different isolation levels:

1. READ UNCOMMITTED: – An uncommitted transaction can be read. This transaction can be rolled back later.

2. READ COMMITTED :- Will not read data of a transaction that has not been committed yet

3. REPEATABLE READ: – Locks placed on all data and another transaction cannot read.

4. SERIALIZABLE:- Does not allow other transactions to insert or update data until the transaction is complete.

4.What are the main components of WCF?
1.Service:The working logic or offering, implemented using any .Net Language.

2.Host: The environment where the service is parked. E.g. exe, process, windows service

3.Endpoints: The way a service is exposed to outside world.

5.What is the difference WCF and Web services?
1. Web services can only be invoked by HTTP. While Service or a WCF component can be invoked by any protocol and any transport type.

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

6.What are contracts in WCF?
The contract is a platform-neutral and standard way of describing WHAT the service does. 
WCF defines four types of contracts,
1 Service contracts
2 Data contracts
3 Fault contracts
4 Message contracts

7.What are Service contracts?
Service contracts describe which operations the client can perform on the service in scope.

There are two types of Service Contracts.
1. ServiceContract - This attribute is used to define the Interface.
2. OperationContract - This attribute is used to define the method inside Interface.

8.What are Data contracts?
Data contracts define which data types can be passed to the service and in return which data types are expected back. 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.
1.DataContract - attribute used to define the custom class
2.DataMember - attribute used to define the custom properties.

In case the DataMember attribute is not specified for a property in the class, the same property can't be passed to the WCF service or can be returned by the WCF service

9. What are Fault contract?
The Fault Contract is a way to communicate error information from a service to a client.

10.What is Message contract?
WCF uses SOAP message for communication and there are situations when you need more control over the SOAP message format. In that case WCF provides Message Contract to customize the message as per requirement

11.What are the Security Modes in WCF ?
The Security Modes are stated below