WCF Interview Questions and Answers
Q1. What is WCF? Briefly explain.
Ans: Windows Communication Foundation is a Software development kit (SDK) to expand and set up offerings in Windows. WCF offers a runtime environment for services. It permits Common Language Runtime (CLR) styles of services to be uncovered, whilst ingesting other services as CLR sorts. WCF is a part of the .NET three.0 framework and it calls for .NET 2.Zero, and it is able to run only on structures that support it.
Q2. What are the principle components of WCF?
Ans: We need to outline three predominant additives in WCF:-
Service magnificence.
Hosting environment
End point
Q3. Explain how does WCF works?
Ans: WCF follows the “Software as a Service” version, in which all units of functionality are described as offerings. For conversation, each point is a portal or connection both with the client or other offerings. It is a program that exposes a collection of endpoints.
Q4. What are the protocols used in Message Layer in WCF ?
Ans: There are a few functionality of protocols that are used in messaging layer in WCF.
Ws-Security Channel:- It allows .To relaxed the message by way of imposing the ws-security specification in the messaging layer of a carrier.
Ws-Reliable Messaging Channel:- This protocols offers guarantee to deliver the message over channels.
Encodes:- It presents the number of encodes for message.
HTTP Channel:- It specifies that HTTP is used for handing over a message.
TCP Channel:- It specifies that TCP is used for delivering the message.
Transaction waft Channel:- It define the sample wherein a message is transacted.
Named Pipe Channel:- It permits inter-method verbal exchange (IPC).
MSMQ Channel:- It allows offerings to inter-perform the MSMQ Applications.
Q5. What are exclusive methods in which WCF can be hosted ?
Ans: The distinct web hosting strategies are
1.IIS website hosting--This is the most commonly used hosting method.Here IIS is
used as a server and has following
advantages -> starts robotically on the primary purchaser request,process recyling.
Disadvantage-- It supports best http protocol
2.Self website hosting-This is hosting the WCF urself either in console/home windows
software additionally in home windows provider .
The host system ought to be going for walks before a customer makes a call to servc.
Its easier to debug and set up.
Lifetime of services can be controlled using Open and Close strategies.
WAS hosting(Windows Activation Server hosting)--WAS changed into introduced
with windows vista and it's miles shipped with IIS 7.Zero. It is extra effective than
three.IIS 6.0 as it may help http,tcp and named pipes while IIS 6.0 can
assist most effective http.
Four.Windows Service Hosting--Here the provider may be programmed to start
whilst the system starts offevolved.
Q6. What is the difference WCF and Web services?
Ans: Web services can handiest be invoked with the aid of HTTP. While Service or a WCF factor may be invoked by way of any protocol and any delivery type. Second internet services are not flexible. However, Services are bendy. If you make a new edition of the service you then need to just expose a new quit. Therefore, offerings are agile and which is a very sensible technique looking at the modern-day commercial enterprise developments.
Q7. What is the Message Layer in WCF ?
Ans: The message layer specifies the pattern of changing information among channels that are used for the duration of carrier communique.
There are varieties of channels utilized in WCF.
Transport layer:- HTTP,Named pipes,TCP and MSMQ are used in transport layer.
Protocol :- WS-Security and WS-Reliability are protocols that used in WCF Applications.
Q8. How transaction works in WCF?
Ans: When we say Transaction, it approach more than one celebration will be concerned so as to finish one single logical operation. In case of SOA birthday celebration approach carrier.
Normally WCF transaction comply with faces. In Phase 1 Transaction manager exams whether all offerings have completed their paintings and geared up to commit. This segment is called as put together phase. If it’s performed then in Phase 2 actual devote occurs which is termed as Commit Phase.
Q9. What is message Contract in WCF ?
Ans: A Message contract offers control over the easy item get entry to protocol (SOAP).Message which are produced and consumed by means of WCF. It facilitates to direct get admission to to the SOAP header and our bodies to change the SOAP Message as on your requirement.The most vital function of SOAP Message is interoperability.
Q10. What is .Svc file?
Ans: Its the file wherein provider is described and it'll be the factor of contact from the clients.It carries name of provider and code behind file name.It is used to realize approximately the carrier.
Q11. What are different bindings supported through WCF?
Ans: WCF consists of predefined bindings. They cover maximum of bindings widely needed in daily application. However, just incase you discover which you need to define something custom WCF does not prevent you. So let us attempt to apprehend what each binding presents.
BasicHttpBinding: - This binding is used whilst we need to use SOAP over HTTP. This binding also can be configured to be used as HTTPS. It can be also configured to ship information in plain text or in optimized shape like MTOM.
WsHttpBinding: - It is identical like BasicHttpBinding. In brief, it uses SOAP over HTTP. But with it also helps reliable message transfer, security and transaction. WS-Reliable Messaging, safety with WS-Security, and transactions with WS-Atomic Transaction supports dependable message.
NetTcpBinding: - This binding sends binary-encoded SOAP, along with support for dependable message switch, security, and transactions, directly over TCP. The largest downside of NetTcpBinding is that each server and purchaser ought to be also made in .NET language.
NetMsmqBinding: - This binding sends binary-encoded SOAP over MSMQ. This binding can most effective be used for WCF-to-WCF communication.
NetNamedPipesBinding:-Ths binding Sends binary-encoded SOAP over named pipes. This binding is best usable for WCF-to-WCF communique among methods on the equal Windows-based totally device.
Note: - An interprocess manage (IPC) protocol is used for replacing statistics among two applications, likely going for walks on unique computers in a community. The difference between Named pipes and TCP is that named pipes have properly overall performance in phrases of communication with in strategies. But when it comes to communicate across community TCP holds the best desire. So in case you are using WCF to speak with process it’s the fine preference to use in phrases for overall performance. Named pipes do now not perform when the site visitors is heavy compared to TCPIP.
Q12. Where the transaction supervisor does is living, in provider aspect or purchaser aspect?
Ans: At patron side
Q13. What is Service Contract in WCF ?
Ans: A service settlement is a contract that defines the operations or methods to be had at quit factors .It also defines the message exchange sample consisting of behavior of the message in one way,duplex or request/respond.
Q14. What do you imply through ABC in WCF ?
Ans: ABC in WCF approach -
Address -> A stands for Address. It suggests wherein you provider is placed.A URL is used to point to the area.Depending on whethere the carrier is hosted in http,tcp... The cope with varies. Eg-
http://localhost/Test
internet.Tcp//localhost/Test
Binding ->B stands for Binding which specifies how the client need to talk with the carrier.
Contract->C stands for contracts. It exposes the operation supplied by means of the Service. It is a agreement.
Q15. What is SOAP in WCF ?
Ans: SOAP stands for Simple Object Access Protocol. A Message settlement provides control over the simple item get right of entry to protocol (SOAP).The most important function of SOAP Message is interoperability.
Q16. What are the numerous methods of web hosting a WCF provider?
Ans: There are three fundamental ways to host a WCF service:-
Self-web hosting the carrier in his own application domain. This we've already included inside the first segment. The service is available in to lifestyles while you create the object of Service Host magnificence and the carrier closes while you call the Close of the Service Host elegance.
• Host in utility area or method provided with the aid of IIS Server.
• Host in Application area and system supplied by WAS (Windows Activation Service) Server.
Q17. What is Activation and web hosting Layer in WCF?
Ans: The activation and hosting layer renders diverse alternatives for the services in which they may be activated as well as hosted. We are able to host asp.Internet application services in methods.
Self hosting (ex. Window application,window provider,console software.)
External server hosting (ex. IIS ,WAS)
Q18. How it is feasible?
Ans: Because both could be the use of WS-Automic protocol for dealing with services.
Q19. What is an endpoint in WCF ?
Ans: ABC together represent an endpoint.Endpoint affords the customer access to the capability exposed through the service.
Q20. What is MEPs in WCF ?
Ans: MEPs stands for Message Exchange Patterns. There are 3 styles of Message Exchange Patterns as given under:-
Request and Response
Data Gram
Duplex (1/2 and complete)
Q21. What do you suggest by means of contarcts. What are the unique sorts of contracts ?
Ans: Contracts are preferred manner of describing the operations performed by using a Service.Diff varieties of contracts are--
1.Service Contracts
It describes the operations provided by using the provider.WCF provider
should have atleast one ServiceContract.It has two attribute-
[ServiceContract] --Used to define the interface.Client can communicate to offerings through interfaces.
Similar to [Webservice] attribute in Webservice
[OperationContract]-Used to outline methods in the interface.Similar to
[WebMethods]
eg-
[ServiceContract()]
public interface ISimpleCalculator
[OperationContract()]
int Add(int a, int b);
DataContract
This defines the records that's exchanged among the client and the service.
These are used manily for used defined objects.They are of sorts
[DataContract]--defines the class
[DataMember] --defines the homes.
Eg-
[DataContract]
magnificence Name
public string Fullname;
[DataMember]
public string FirstName;
[DataMember]
public string SurName;
Inbuilt kinds like string (Fullname) are defined impicitly and that they do now not want
facts contracts.
3.Fault Contracts.
These are used to deal with mistakes in a provider.When a carrier throws an error it
does no longer reach the patron facet. But via the usage of fault settlement we are able to come to know the
error that is raised by means of the carrier.
Eg-
[ServiceContract()]
public interface ISimpleCalculator
[OperationContract()]
[FaultContract(typeof(ArgumentException))]
int Add(int a, int b);
Raise the exception as
throw new FaultException("error") ;
4.Message Contracts
Message Contract defines the manner messages are transferred the usage of SOAP messages. It
is used if you need to personalize the SOAP layout.
Eg-
[MessageContract]
public elegance CustomerDetails
[MessageHeader]
public string CustID;
[MessageBodyMember]
public string Name;
Q22. What is Policy binding in WCF ?
Ans: The Policy and Binding issue of the settlement layer specifies critical records.Such as protection and protocol of a WCF offerings. Binding is a manner used to enable conversation between services and clients.There are a few protocols that are very important to communications with the quit factor of offerings.ExHTTP,TCP,MSMQ.
Q23. What is WCF Method Overloading
Ans: Hello folks, I have already defined concerning Transfer huge record using WCF and The remote server again an sudden response: (413) Request Entity Too Large. Today I am going to provide an explanation for another properly idea of WCF Method Overloading.
As you all understand approach overloading is supported by way of .Internet Framework. So WCF also helps technique overloading, however how may want to we gain WCF technique Overloading!!!
Q24. What all things we have to do that allows you to achieve WCF Transaction?
Ans: 1.All operation contracts need to be embellished with TransactionFlow characteristic
2.While enforcing Operation Contract specify OperationBehavior characteristic setting TransactionScopeRequired to proper.
Three.Enable transaction glide for binding in Web.Config
4. While invoking each carrier at patron facet use TransactionScope
Q25. What is Service RunTime Layer in WCF ?
Ans: The service runtime layer specifies and manipulate distinctive behavior of a provider that arise throughout its operation such as ingesting or website hosting the offerings.
Q26. What’s the distinction among Allowed and Mandatory in TransactionFlow characteristic?
Ans: TransactionFlowOption.Allowed method patron can name the service in transaction if he/she desires.
TransactionFlowOption.Mandatory approach consumer must name the provider in transaction.
Q27. What are the conduct controlled with the aid of Service RunTime Layer in WCF ?
Ans: Throttling behavior:- The wide variety of processed messages varies in step with call for of offerings.
Error Behavior:- It specifies the action to be taken, it only of the message give errors at some point of carrier runtime.
Instance behavior:- It specifies the range of carrier example which are available to system a message.
Meta Data Behavior:- It specifies ,meta information is available or now not across the community.
Message Inspection:- It inspects all the message in the course of provider runtime.
Transaction behavior:- It roll backs the transactions, if any manner fails for the duration of provider runtime.
Dispatch Behavior:- It determines ,how a message is dealt with and processed by the WCF infrastructure.
Concurrency conduct:- It specifies whether the message are processed sequentially or concurrently by using the service.
Parameter filtering:- It filters the message header and executes preset moves.
Q28. What namespace is used to get admission to the WCF ?
Ans: System.ServiceModel

