Showing posts with label WCF Interview Questions. Show all posts
Showing posts with label WCF Interview Questions. Show all posts

Wednesday, 4 December 2013

What is .svc file in WCF?

.svc file is a text file. This file is similar to our .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

What is XML Infoset?

The XML Information Set defines a data model for XML. It is an abstract set of concepts such as attributes and entities that can be used to describe a valid XML document. According to the specification, "An XML document's information set consists of a number of information items; the information set for any well-formed XML document will contain at least a document information item and several others."

What is Message Contract in WCF?

Message Contract is the way to control the SOAP messages, sent and received by the client and server. It can be used to add and to get the custom headers in SOAP message Because of Message Contract we can customize the parameters sent using SOAP message between the server and client.

What is service host factory in WCF?

Service host factory is the mechanism by which we can create the instances of service host dynamically as the request comes in. This is useful when we need to implement the event handlers for opening and closing the service. WCF provides ServiceFactory class for this purpose.

How we can use MessageContract partially with DataContract for a service operation in WCF?

MessageContract must be used all or none. If we are using MessageContract into an operation signature, then we must use MessageContract as the only parameter type and as the return type of the operation.

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.

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.

How we can achieve Operation Overloading while exposing WCF Services?

By default, WSDL doesn’t support operation overloading. Overloading behavior can be achieved by using "Name" property of OperationContract attribute.
[ServiceContract]
interface IMyCalculator
{
   [OperationContract(Name = "SumInt")]
   int Sum(int arg1,int arg2);

   [OperationContract(Name = "SumDouble")]
   double Sum(double arg1,double arg2);
}
When the proxy will be generated for these operations, it will have 2 methods with different names i.e. SumInt and SumDouble.

What are the possible ways of hosting a WCF service?

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
a.Console Application
b.Windows Application
c.Windows Service
2.Hosting on Web Server
a.IIS 6.0 (ASP.NET Application supports only HTTP)
b.Windows Process Activation Service (WAS) i.e. IIS 7.0 supports HTTP, TCP, NamedPipes, MSMQ.

What are WCF Service Endpoints?

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.