Saturday 27 July 2013

WCF interview questions



          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.

             It is a Software development kit for developing services on Windows. WCF is introduced in .NET 3.0. In the System.ServiceModel namespace. WCF is based on basic concepts of Service oriented architecture (SOA)

1)      What are contracts in WCF?

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.


[ServiceContract]
interface IMyContract
{
   [OperationContract]
   string MyMethod( );
}
class MyService : IMyContract
{
   public string MyMethod( )
   {
      return "Hello World";
   }
}


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.


[DataContract]
class Contact
{
   [DataMember]
   public string FirstName;

   [DataMember]
   public string LastName;

}


If DataMember attributes are not specified for a properties in the class, that property can't be passed to-from web service.

Fault contracts

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


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.


2)      Where we can host WCF services?

Every WCF services must be hosted somewhere. There are three ways of hosting WCF services. 

They are 

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

                 3)      What is endpoint in WCF? 


           It describes the actual behavior or operation of the service at runtime

                4)       What are duplex contracts in WCF? 

               WCF Services can communicate with client through a callback - is called duplex messaging                           pattern.Duplex messaging in WCF can be done over different transports, like TCP, Named Pipes                 and even HTTP

                5)      What are the various ways of hosting a WCF service? 

1. Self hosting: - The service code is embedded within the application code. An end point for the service is defined and an instance of SeriveHost is created. A method can be written then to call the service.

2. Managed Windows services: - here, some hosting code is written in the application code. It consists of registering the application domain as a windows service.

3. Internet Information Services: - Does not require any hosting code to be written in the application code. IIS host services can only use HTTP transport mechanism. IIS needs to be installed and configured on the server.

4. Windows process activation service:- Does not require any hosting code to be written in the application code. WAS needs to be installed and configured on the server. WCF uses the listener adapter interface to communicate activation requests. Requests are transported over non HTTP protocols.

      6)       What are 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.

     7)      What are the types of binding available in WCF?
A binding is identified by the transport it supports and the encoding it uses. Transport may be HTTP,TCP etc and encoding may be text,binary etc. The popular types of binding may be as below:
a)BasicHttpBinding
b)NetTcpBinding
c)WSHttpBindingl
d)NetMsmqBinding

      8)      What is the proxy for WCF Service?
A proxy is a class by which a service client can Interact with the service.
By the use of proxy in the client application we are able to call the different methods exposed by the service

      9)      What is the difference between WCF Service and Web Service?

a)WCF Service supports both http and tcp protocol while webservice supports only http protocol.
b)WCF Service is more flexible than web service.
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.

     10)  What is Transport reliability?

Transport reliability (such as the one offered by TCP) offers point-to-point guaranteed delivery at the network packet level, as well as guarantees the order of the packets. Transport reliability is not resilient to dropping network connections and a variety of other communication problems. 

     11)  What is Message reliability?

Message reliability deals with reliability at the message level independent of how many packets are required to deliver the message. Message reliability provides for end-to-end guaranteed delivery and order of messages, regardless of how many intermediaries are involved, and how many network hops are required to deliver the message from the client to the service.
                              
      12)  What was the code name for WCF?

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+

No comments:

Post a Comment