Top 20 WCF Interview Questions and Answers

Shailendra Chauhan  Print   13 min read  
21 Dec 2018
24 Jun 2019
6.35K

WCF is Microsoft's unified programming model for building service-oriented applications. It enables developers to build secure, reliable, transacted solutions that can be integrated across platforms and interoperate with existing. This article contains the top 20 WCF interview questions and answers, in order to prepare you for the interview.

  1. What is SOA?

    SOA stands for Service Oriented Architecture. It is an architectural design pattern which states that every component of a system should be a service (here service means a unit of a program that serves a business process), and the system should be composed of several loosely-coupled services means services should be independent of each other, so that changing one of them should not affect any other services.

  2. What are Service Oriented Design Principles?

    There are four Service-oriented principles (tenets) in SOA as given below :

    1. Boundaries are explicit: This SOA principle states that a service can be deployed anywhere and be easily and freely accessed by other services, regardless of the environment or development language of the other services.

    2. Services are autonomous: This SOA principle states that each service must be managed and versioned differently so that they do not affect other services in the process. Contracts, once published, should not be changed. Services need to be isolated and decoupled to accomplish the goal of making them autonomous.

    3. Services share schema and contract, not class: This SOA principle states that services should not pass classes and types; they pass schemas (data) and contracts (behaviors). This allows for a loosely coupled system where the service does not care what type of environment the other service is executing on. The information being passed is 100% platform independent.

    4. Service compatibility is determined based on policy: This SOA principle states that each service should have its own compatibility level and knows how it would interact with other services. Services look at each other’s policy, looking for similarities so that they can start communicating. If two services can’t satisfy each other’s policy requirements, they are not compatible with each other.

  3. What is SOAP?

    SOAP stands for Simple Object Access Protocol which is used for exchanging data in XML-based format over HTTP. SOAP is widely-used by web services for exchanging data. A simple SOAP message structure is given below:

     <soap:Envelope xmlns:soap=”http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
     <soap:Body xmlns:m="http://www.mysite.com/books">
     <m:Book>
     <m:BookName>WCF and Web Services Interview Questions and Answers</m:BookName>
     </m:Book>
     </soap:Body>
     </soap:Envelope>
    

    A SOAP message has an optional header and a required body element. A SOAP message header can contain the application-specific information like authentication or authorization etc. Also, a SOAP message header must be the first child element of the SOAP Envelope element. The SOAP body element contains the actual SOAP message. Moreover, SOAP is a combination of HTTP protocol and XML i.e. SOAP = HTTP + XML

  4. What is WS -* Protocols?

    The SOAP protocol is used for message exchange between Web Services. But SOAP defines very basic semantics for message headers. It does not always define meaning to the header. Hence to extend SOAP, WS-* protocols specifications have been developed with semantics which can then be reused in various application scenarios.

    WS -* protocols are a set of protocols (means standards and specifications) that helps us to implement certain needs and behaviors of a service. These protocols describe how to exchange messages in a secure, transactional, and reliable way by using the headers in the SOAP message. WCF can implement the WS -* protocols by using WsHttpBinding. This binding makes use of some of the WS -* protocols and adds the needed behaviors, such as transactional message calls, reliability, discovery, and addressing.

  5. What are the differences between ASP.NET Web Service and WCF?

    The differences between ASP.NET Web Service and WCF are given below:

    WCF
    ASP.NET Web Service
    ServiceContract and OperationContract attributes are used for defining WCF service.
    WebService and WebMethod attributes are used for defining web service.
    Supports various protocols like HTTP, HTTPS, TCP, Named Pipes and MSMQ.
    Supports only HTTP, HTTPS protocols.
    Hosted in IIS, WAS (Windows Activation Service), Self-hosting, Windows Service.
    Hosted only in IIS.
    Supports security, reliable messaging, transaction and AJAX and REST supports.
    Support security but is less secure as compared to WCF.
    Supports DataContract serializer by using System.Runtime.Serialization.
    Supports XML serializer by using System.Xml.Serialization.
    Supports One-Way, Request-Response, and Duplex service operations.
    Supports One-Way and Request-Response service operations.
    WCF is faster than Web Services.
    Web Services are slower than WCF
    HashTable can be serialized.
    HashTable cannot be serialized. It can serialize only those collections which implement IEnumerable and ICollection.
    Unhandled Exceptions does not return to the client as SOAP faults. WCF supports better exception handling by using FaultContract.
    Unhandled Exceptions returns to the client as SOAP faults.
    Supports XML, MTOM, Binary message encoding.
    Supports XML and MTOM (Message Transmission Optimization Mechanism) message encoding.
    Supports multi-threading by using ServiceBehaviour class.
    Doesn’t support multi-threading.
  6. What is WCF?

    WCF is a programming model for building and developing the service-oriented application. WCF allows applications to communicate with each other in a distributed environment. WCF is a set of technologies that covers ASMX web services, Web Services Enhancements (WSE), .NET Remoting and MSMQ. The purpose of WCF is to provide a single programming model that can be used to create services on the .NET platform for organizations.

  7. What is WCF ABC?

    WCF ABC stands for Address, Binding, and Contract.

    Address (Where)

    WCF Address specifies to a specific location, where the service is hosted. A WCF Address is specified as a URI. URI’s first part specifies the transport protocol (HTTP, TCP, Net.pipe and MSMQ), and the other parts specify the host machine address and service path as shown in below fig.

    WCF address example

    Others sample Addresses are given below:

     
     http://www.mywebsite/MyService
     net.tcp://www.mywebsite/MyService
     net.pipe://www.mywebsite/MyPipeService
     net.msmq://www.mywebsite/MyMsMqService
    

    Binding (How)

    WCF binding specifies how the service and client will communicate with each other in terms of transport protocols and encoding (such as text or binary). WCF binding is a set of binding elements and each element specify, how the service and client will communicate with each other. Each binding must have at least one transport element and one message encoding element.

    Contract (What)

    WCF contract specifies what the service contains. WCF has five types of contracts: service contract, operation contract, data contract, message contract and fault contract. Each contract defines certain behavior.

  8. How to define multiple endpoints for a WCF service?

    A WCF service configuration with multiple endpoints is given below :

     <system.serviceModel>
     <services >
     <service name = "MyWCFService">
     <endpoint address = "http://localhost:90/MyWCFService" 
     binding = "wsHttpBinding" contract = "IMyWCFContract"/>
     <endpoint address = "net.tcp://localhost:91/MyWCFService"
     binding = "netTcpBinding" contract = "IMyWCFContract"/>
     </service> 
     </services>
     </system.serviceModel>
    
  9. What are default Endpoints?

    WCF offers some default endpoints to the service if a service host doesn’t define any endpoints but has at least one base address. For example, WCF uses the basic binding for the Http address.

  10. What are standard Endpoints?

    WCF provides a set of pre-defined endpoints known as Standard Endpoints for metadata exchange, discovery and web. You can configure the standard endpoints by using a config file and programmatically. Here is the list of standard endpoints :

    • mexEndpoint

    • webHttpEndpoint

    • webScriptEndpoint

    • workflowControlEndpoint

    • announcementEndpoint

    • discoveryEndpoint

    • udpAnnouncementEndpoint

    • udpDiscoveryEndpoint

  11. What are the different WCF contracts?

    WCF contract specifies the service and its operations. WCF has five types of contracts:

    1. Service contract

    2. Operation contract

    3. Data contract

    4. Message contract

    5. Fault contract.

  12. What are the various ways of hosting a WCF service?

    There are four ways of hosting a WCF service.

    • Self-Hosting

    • Windows services hosting

    • IIS hosting

    • Windows Activation Services hosting (WAS)

  13. What is Binding?

    WCF binding specifies how the service and client will communicate with each other in terms of transport protocols and encoding (such as text or binary). WCF binding is a set of binding elements and each element specify, how the service and client will communicate with each other. Each binding must have at least one transport element and one message encoding element.

  14. What are the different types of bindings in WCF?

    WCF supports the following types of built-in bindings:

    1. Basic binding

    2. Web binding

    3. Web Service (WS) binding

    4. WS Dual binding

    5. TCP binding

    6. IPC binding

    7. MSMQ binding

    8. Federated WS binding

    9. Peer Network binding

    10. MSMQ integration binding

  15. What are the ways to create a WCF Client?

    There are two ways to create a WCF Client or calling a WCF Service as:

    • WCF Proxy

    • Channel factory

  16. What is Instance Management in WCF?

    WCF manages the session by creating the instance of the service class. This created instance(s) handle the incoming service request. In WCF, the session is the way of managing the services instance(s) so that the server can use these instances in an optimized way. At the server side, the InstanceContext class is used to manage service class instance. There are following instance management ways :

    • Per Call

    • Per Session

    • Single

  17. What is Concurrency Management in WCF?

    Concurrency management is closely related to the Instance management in WCF but both are two different things. Instance management specifies how the service instances are created while Concurrency management specifies how many concurrent requests are handled by the service instances. By using concurrency, you can make your service instance thread-safe. By default, a per-call service instance is thread-safe since each request is served by a new service instance. A per-session service instance is not thread-safe since multiple requests of a client are served by a single service instance. Hence, it’s required concurrency management. A single service instance is not thread-safe since multiple requests of all clients are served by a single service instance. Hence, it’s required concurrency management.

  18. What is Impersonation?

    Impersonation is a way to authorize a caller (client) identity to access the service domain’s resources. The service resources may be local files or database tables and should be on the same machine on which service is hosted. By default, impersonation is disabled and resources are accessed by using the WCF service's process identity.

  19. What is service versioning?

    After the initial deployment of the WCF service, you may need to change the service for a variety of reasons like as changing business needs or fixing others issues. Each change in your existing service introduces a new version of the service. Service versioning is helpful in backward compatibility with your existing clients.

  20. What is WCF Data Service?

    WCF Data Services uses OData (Open Data Protocol) protocol for querying or manipulating the data. WCF Data Services is built on top of WCF REST Services. It is a RESTful service to support CRUD operations on the database using the HTTP protocol. It supports all database operations using URI. DATA protocol can expose data from the relational database, File systems, Web sites, services etc. It supports XML or JSON format for exposing the data.

Summary

I hope these questions and answers will help you to crack your WCF interview. These interview Questions have been taken from our new released eBook WCF/Web Services Interview Questions & Answers. This book contains more than 110+ WCF interview questions.

This eBook has been written to make you confident in WCF with a solid foundation. Also, this will help you to turn your programming into your profession. It's would be equally helpful in your real projects or to crack your WCF Interview.

Buy this eBook at a Discounted Price!

WCF/Web Services Interview Questions & Answers eBook

Take our free skill tests to evaluate your skill!

In less than 5 minutes, with our skill test, you can identify your knowledge gaps and strengths.

Learn to Crack Your Technical Interview

+
+
Accept cookies and close this message