Hello All, We are going to start new batch from next week. message/call or mail us for more details.

13 September 2013

WCF Interview Question and Answer - DotNet Brother

What is WCF?
Windows Communication Foundation or just WCF is a programming framework used to build applications that communicate with each other. It is a part of the .NET Framework dedicated to communications.

What are the different WCF binding available?
• BasicHttpBinding
• WSHttpBinding
• WSDualHttpBinding
• WSFederationHttpBinding
• NetTcpBinding
• NetNamedPipeBinding
• NetMsmqBinding
• NetPeerTcpBinding
• MsmqIntegrationBinding

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.

What is the difference between XMLSerializer and the DataContractSerializer?
1. DataContractSerializer is the default serializer fot the WCF
2. DataContractSerializer is very fast.
3. DataContractSerializer is basically for very small, simple subset of the XML infoset.
4. XMLSerializer is used for complex schemas

What is endpoint in WCF service?
The endpoint is an Interface which defines how a client will communicate with the service. It consists of three main points: Address,Binding and Contract.

What is the difference between WCF Service and Web Service?
1) WCF Service supports both http and tcp protocol while webservice supports only http protocol.
2) WCF Service is more flexible than web service.
3) WCF is combination of WebService, Remoting, MSMQ

What are the various ways of hosting a WCF service?
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 ServiceHost class and the service closes when you call the Close of the ServiceHost class. Host in application domain or process provided by IIS Server. Host in Application domain and process provided by WAS (Windows Activation Service) Server.

What is service and client in perspective of data communication?
A service is a unit of functionality exposed to the world.
The client of a service is merely the party consuming the service.

List the behaviors that WCF service uses during its execution.
A WCF service uses the following list of behaviors during its execution.
1. Throttling
2. Security
3. Instancing
- PerCall
- PerSession
- Single
4. Error handling
5. Concurrency
- Multiple
- Single
- Reentrant
6. Transactions

What is WCF? Explain.
WCF (A platform for SOA)
Unified programming model, provided by WCF, helps in building Service Oriented Application (SOA) through some simple implementation. WCF Service features for usage in SOA implementation.

Uses of WCF services:
• Expose functionality using contracts to clients
• Can be deployed over various protocols to satisfy various distributed and interoperable scenarios
• Execute autonomously and do not impact another service in case of failure
• Design and implementation are separate from business logic, which eases migration to SOA design

What is the programming life cycle of WCF?
Windows Communication Foundation (WCF) enables applications to communicate whether they are on the same computer, across the Internet, or on different application platforms. This topic outlines the tasks that are required to build a WCF application. The basic tasks to perform, are, in order to:
1. Define the Service Contract
2. Implement the Service Contract
3. Configure the Service by specifying endpoint information and other behavior information
4. Host the service in an application
5. Build the client application

Define WCF data contract
- A data contract is defined by using a Data Contract Attribute on a class or structure.
- Members of the data structure which will be used by the service need to be marked with the Data Member Attribute.
- Only those members will be transferred between the service and its client. In the same way that different classes can implement the same interface, different classes can implement the same Data Contract, and can serialize and deserialize the same data.

What is the advantage and disadvantage of implementing IExtensibleDataObject?
WCF guidelines recommend enhancing all data contracts with support of IExtensibleDataObject interface, to preserve unexpected data from clients. During deserialization, superfluous data is placed in a dictionary on the service side and during serialization, the same data is written as XML as it was originally provided by the client. This is very useful to preserve data from version 2.0 services at a version 1.0 client. It is also useful in case where downstream calls from version 2.0 services go to other services handling version 1.0.
However, there is also a disadvantage of implementing IExtensibleDataObject. It carries risks of denial of service (DoS) and unnecessary use of server resources.

What is the role of WSDL in WCF?
WSDL stands for Web Service Description Language. The WCF service exposes the WSDL document for the clients, to generate proxies and the configuration file. The WSDL file provides the following information for the consumers of the WCF service.
1. Provides the information about the service contract and operations available.
2. Provides the information about all the end points exposed by the WCF service.
3. Provides the information about the messages and types that can be exchanged between the client and the WCF service.
4. WSDL also provides any information about the policies used.

What are the different types of bindings available in WCF?
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 usHTTP 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.

What are Various Ways of Hosting WCF Services?
Three ways of hosting WCF Services:
1. Self-hosting the service in its own application domain. The service comes into existence when you create the object of Service Host class and the service closes when you call the Close of the Service Host class.
2. Host in application domain or process provided by IIS Server.
3. Host in application domain and process provided by WAS (Windows Activation Service) Server.