WCF (Windows Communication Foundation) Interview questions
1- What is Windows Communication Foundation (WCF) ?
WCF is a framework to create a service-oriented application. WCF services can send the data asynchronously from one endpoint service to another service. The endpoint service can be the part of the continuous available service that is hosted by the IIS. WCF sends the data asynchronously. It is a secure service to process the business transaction. The message that is send can be a single character or a word sent as XML.
2- When to choose WCF?
- Choose WCF when you want to create a service that should support special scenarios such as one way messaging, message queues, duplex communication etc.
- Choose WCF when you want to create a service that can use fast transport channels when available, such as TCP, Named Pipes, or maybe even UDP (in WCF 4.5), and you also want to support HTTP when all other transport channels are unavailable.
When to choose Web API?
- Choose Web API when you want to create a resource-oriented services over HTTP that can use the full features of HTTP (like URIs, request/response headers, caching, versioning, various content formats).
- Choose Web API when you want to expose your service to a broad range of clients including browsers, mobiles, iPhone and tablets.
3- Difference between ASP.NET Web API and WCF (Windows Communication Foundation )
|Web API||WCF (Windows Communication Foundation )|
|Open source and ships with .NET framework.||Ships with .NET framework|
|Supports only HTTP protocol.||Supports HTTP, TCP, UDP and custom transport protocol.|
|Maps http verbs to methods||Uses attributes based programming model.|
|Uses routing and controller concept similar to ASP.NET MVC.||Uses Service, Operation and Data contracts.|
|Does not support Reliable Messaging and transaction.||Supports Reliable Messaging and Transactions.|
|Web API can be configured using HttpConfiguration class but not in web.config.||Uses web.config and attributes to configure a service.|
|Ideal for building RESTful services.||Supports RESTful services but with limitations.|