WCF Interview Questions and Answers

1. What is WCF ?

Windows Communication Foundation (WCF) a set of APIs under.NET Framework for developing connected and service-oriented applications. It is developed by Microsoft that is used to build service-oriented applications. Earlier it used to be known as Indigo. Through WCF, you can establish communication channels using MSMQ, Remoting etc. Using it, you can send data as asynchronous messages from one service endpoint to another.

2. What are the components used in WCF?

Components of WCF are service class, end point and hosting environment.

3. What is Endpoint?

In WCF, the end point is the address where a message is to be sent or received. WCF client connects to WCF service through an endpoint. It also explains how the messages will be sent with the set of messages. It has three properties which are address, binding and contracts.

4. Does WCF support interoperability?

Yes, WCF supports interoperability with WCF applications on the same Windows machine or on a different Windows machines or on platforms such as Java running on Windows or even other operating systems.

5. What are the features of WCF?

WCF has following features -

  • Simple Configuration
  • Interoperability
  • UDP Endpoint Support
  • Service Metadata
  • Security
  • Web Socket Support
  • Extensibility
  • Reliable and Queued Messages
  • Streaming Improvements
  • Asynchronous Support

6. What are the advantages of using WCF?

WCF has following advantages -

  • It supports interoperability
  • It can be hosted on IIS, WAS (Windows Activation Service), Windows services or Self hosting.
  • Its services offer enhanced reliability
  • Its services are more secured as compared to other Active Server Methods as it has a default security mechanism
  • It is flexible and extensible like Remoting
  • It has integrated AJAX and supports JSON as well
  • It supports XML, SOAP and REST

7. Differentiate between WCF Service and ASP.NET Web Services.

WCF Service - Windows Communication Foundation (WCF) a set of APIs under.NET Framework for developing service-oriented applications. ServiceContract and OperationContract attributes are used for defining WCF service. WCF service supports HTTP, WS-HTTP, TCP, Custom, Named Pipes, MSMQ & P2P (Point to Point) etc. protocols. It can be hosted on IIS, WAS (Windows Activation Service), Windows services or Self hosting. WCF services are more secured than those of ASP.NET Web Services because WCF does not need IIS to run, it can run as a System Service on the Server. It supports One-Way, Request-Response and Duplex service operations. Hash Table can be serialized.
ASP.NET Web Services - Web service is a technique to provide data as a service/response over the HTTP protocol on request of any other program. WebService and WebMethod attributes are used for defining web service. It supports HTTP & HTTPS protocols. Hosted only in IIS. It is less secured as compared to WCF to protect the data between Server and Client. The supported operations are One-Way and Request-Response type. Hash Table cannot be serialized.

8. What are different types of contracts available in WCF?

Following 4 types of contracts are available in WCF-

  • Data Contracts
  • Service Contracts
  • Message Contracts
  • Fault Contracts

9. What is Data Contracts in WCF?

A data contract is an exchange of data agreement between a service and a client. For security purpose, we serialize the messages sent across the wire “[DataContact]” attribute given at class level to serialize the class by using “[Datamember]” attribute over properties. It defines the external format of data passed to and from service operations.

10. What is Service Contracts in WCF?

Service contracts give details of the operations that the services will perform Service Contracts can be defined like –[ServiceContract]. It links the interface and methods of the service to a platform-independent description. Some of the service operations are one-way; some may have request-response operations.