Friday, 23 August 2013

DOTNET WCF INTERVIEW QUESTIONS - MANOHAR GOUD TRAINER FACULTY GURU




What is the difference between WCF and ASMX Web Services?

Simple and basic difference is that ASMX or ASP.NET web service is designed to send and receive messages using SOAP over HTTP only. While WCF can exchange messages using any format (SOAP is default) over any transport protocol (HTTP, TCP/IP, MSMQ, NamedPipes etc).


What are WCF Service Endpoints? Explain.

For Windows Communication Foundation services to be consumed, it’s necessary that it must be exposed; Clients need information about service to communicate with it. This is where service endpoints play their role.
A WCF service endpoint has three basic elements i.e. Address, Binding and Contract.
  • Address: It defines "WHERE". Address is the URL that identifies the location of the service.
  • Binding: It defines "HOW". Binding defines how the service can be accessed.
  • Contract: It defines "WHAT". Contract identifies what is exposed by the service.

What are the possible ways of hosting a WCF service? Explain.

For a Windows Communication Foundation service to host, we need at least a managed process, a ServiceHost instance and an Endpoint configured. Possible approaches for hosting a service are:
  1. Hosting in a Managed Application/ Self Hosting
    1. Console Application
    2. Windows Application
    3. Windows Service
  2. Hosting on Web Server
    1. IIS 6.0 (ASP.NET Application supports only HTTP)
    2. Windows Process Activation Service (WAS) i.e. IIS 7.0 supports HTTP, TCP, NamedPipes, MSMQ.

What Message Exchange Patterns (MEPs) supported by WCF? Explain each of them briefly.
1. Request/Response 2. One Way 3. Duplex

Request/Response

It’s the default pattern. In this pattern, a response message will always be generated to consumer when the operation is called, even with the void return type. In this scenario, response will have empty SOAP body.

One Way

In some cases, we are interested to send a message to service in order to execute certain business functionality but not interested in receiving anything back. OneWay MEP will work in such scenarios. If we want queued message delivery, OneWay is the only available option.

Duplex

The Duplex MEP is basically a two-way message channel. In some cases, we want to send a message to service to initiate some longer-running processing and require a notification back from service in order to confirm that the requested process has been completed.

What is DataContractSerializer and How its different from XmlSerializer?

Serialization is the process of converting an object instance to a portable and transferable format. So, whenever we are talking about web services, serialization is very important.
Windows Communication Foundation has DataContractSerializer that is new in .NET 3.0 and uses opt-in approach as compared to XmlSerializer that uses opt-out. Opt-in means specify whatever we want to serialize while Opt-out means you don’t have to specify each and every property to serialize, specify only those you don’t want to serialize. DataContractSerializer is about 10% faster than XmlSerializer but it has almost no control over how the object will be serialized. If we wanted to have more control over how object should be serialized that XmlSerializer is a better choice.


Q:What is Contracts in WCF ?
ServiceContracts
OperationContracts
DataContracts
Q: What is endpoint in WCF? 
It describes the actual behavior or operation of the service at runtime
Q: What is 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
Q: 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.
Q: 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.
Q: What is InstanceContextMode in WCF? 
This property value indicate when new service objects are created ? the property has three value
the default is PerSession1. PerCall:
2. PerSession:
3. Single:
Q: What is ConcurrencyMode in WCF? 
This property value indicate how service supports thread? the property has three value
the default is PerSession1. Single:
2. Multiple :
3. Reentrant :




What is WCF?
Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application. An endpoint can be a client of a service that requests data from a service endpoint. The messages can be as simple as a single character or word sent as XML, or as complex as a stream of binary data.
Where it can be used in Real Time?
·         A secure service to process business transactions.
·         A service that supplies current data to others, such as a traffic report or other monitoring service.
·         A chat service that allows two people to communicate or exchange data in real time.
·         A dashboard application that polls one or more services for data and presents it in a logical presentation.
·         Suppose you have an organization who develops WCF services for the clients. It is possible that your client can develop the user interface of the required application in any programming language. So that he can easily develop the requirement simply from the WebServices.
·         Also it can be developed in N tier application which separates the business logic and the Data access layer with the user interface.

Features of WCF?

·         Service Orientation
·         Interoperability
·         Multiple Message Patterns
·         Data Contracts
·         Security
·         Multiple Transports and Encodings
·         Reliable and Queued Messages
·         Durable Messages
·         Transactions
·         AJAX and REST Support
·         Extensibility

Difference between WebServices and WCF?

Webservices
WCF
It can only be hosted in IIS
It can be hosted in IIS, Windows service, self-Hosting, Windows activation Service
[WebService] attribute has to be added.
[ServiceContract] attribute has to be added to the class.
It is a simple procedural programming type
It can be done with Structural or OOPs Programming
One-Way and Request-response are the Operations supported in WebService.
One-Way, Request-Response and Duplex are the Operations supported in WCF
System.xml.Serialization namespace is needed for Serialization
System.Runtime.Serialization namespace is needed for Serialization
Encoding:-XML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, Custom
Encoding:- XML 1.0, MTOM, Binary, Custom
Can be accessed through HTTP, TCP, Custom
Can be accessed through HTTP, TCP, Named pipes, MSMQ,P2P, Custom
Uses SOAP over Http only
Can be accesses through any Format(SOAP is Default) using (HTTP,TCP/IP, MSMQ, NamedPipes etc).
ASMX Security is limited. Normally authentication and authorization is done using IIS and ASP.NET security configuration and transport layer security.
WCF provides a consistent security programming model for any protocol and it supports many of the same capabilities as IIS and WS-* security protocols, additionally, it provides support for claim-based authorization that provides finer-grained control over resources than role-based security
ASMX web services uses XmlSerializer
WCF uses DataContractSerializer which is far better in performance
Cannot be Multithreaded
Can be multithreaded via ServiceBehavior Class
It is Homogeneous. Can communicate with one end point only at a time.
WCF is Heterogeneous. Can communicate with more that one end point at a time.
File Extension is .asmx
File extension is .svc
In ASP.NET Web services, unhandled exceptions are returned to the client as SOAP faults.
In WCF Services, unhandled exceptions are not returned to clients as SOAP faults. A configuration setting is provided to have the unhandled exceptions returned to clients for the purpose of debugging.

Difference between XMLSerializer and  DataContractSerializer?

·         A practical benefit of the design of the DataContractSerializer is better performance overXmlserializer.
·         XML Serialization does not indicate which fields or properties of the type are serialized into XML whereas DataCotractSerializerExplicitly shows the which fields or properties are serialized into XML.
·         The DataContractSerializer can translate the HashTable into XML which cannot be done with XMLSerializer.

·         Serialization is the process of converting an object instance to a portable and transferable format. So, whenever we are talking about web services, serialization is very important.

·         Windows Communication Foundation has DataContractSerializer that is new in .NET 3.0 and uses opt-in approach as compared to XmlSerializer that uses opt-out. Opt-in means specify whatever we want to serialize while Opt-out means you don’t have to specify each and every property to serialize, specify only those you don’t want to serialize. DataContractSerializer is about 10% faster than XmlSerializer but it has almost no control over how the object will be serialized. If we wanted to have more control over how object should be serialized that XmlSerializer is a better choice.

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.

 Explain Address,Binding and contract for a WCF Service?
Address: Address defines where the service resides.
Binding: Binding defines how to communicate with the service.
Contract: Contract defines what is done by the service.

What are the various address format in WCF?
a)HTTP Address Format:--> http://localhost:
b)TCP Address Format:--> net.tcp://localhost:
c)MSMQ Address Format:--> net.msmq://localhost:

 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)WSHttpBinding
d)NetMsmqBinding

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 are WCF Service Endpoints? Explain.
For Windows Communication Foundation services to be consumed, it’s necessary that it must be exposed; Clients need information about service to communicate with it. This is where service endpoints play their role.
A WCF service endpoint has three basic elements i.e. Address, Binding and Contract.
·         Address: It defines "WHERE". Address is the URL that identifies the location of the service.
·         Binding: It defines "HOW". Binding defines how the service can be accessed.
·         Contract: It defines "WHAT". Contract identifies what is exposed by the service.



No comments:

Post a Comment