WCF (Windows Communication Foundation) Interview Questions

This section covers frequently asked WCF interview questions.

1. What is WCF?

WCF (Windows Communication Foundation) is a Microsoft framework for building service-oriented applications. It allows you to create services that can communicate with clients over various protocols (like HTTP, TCP, etc.). It simplifies creating, configuring, and deploying services.

2. WCF Service Endpoints.

A WCF service exposes one or more endpoints. Each endpoint has three parts:

  • Address: The URI (Uniform Resource Identifier) specifying the endpoint's location.
  • Binding: Defines how clients communicate with the endpoint (transport, encoding, security, etc.).
  • Contract: Specifies the operations a client can perform (what the service exposes).

3. Essential WCF Components.

  • Service class: Defines the service's functionality.
  • Endpoints: Communication points for clients.
  • Hosting environment: The process hosting the service (like IIS or a custom application).

4. Endpoint Address Property.

Specifies the URI of the endpoint.

5. Endpoint Binding Property.

Defines the communication protocol and settings (transport, encoding, security).

6. Endpoint Contract Property.

Defines the operations exposed by the endpoint (interface).

7. What is a Service?

A service is a self-contained unit of functionality accessible remotely. Service-oriented architecture (SOA) is a design approach based on the concept of services.

8. WCF Service Proxy.

A service proxy is a client-side object that acts as an intermediary for communication with a WCF service. It simplifies interaction with the service by providing a local representation.

9. Service Contracts.

A service contract defines the operations that a client can call. It's typically defined using an interface with the [ServiceContract] attribute in .NET.

10. Instance Modes in WCF.

  • Per call: A new instance is created for each method call.
  • Per session: A single instance is used for the entire client session.
  • Singleton: A single instance serves all clients.

11. "Per Call" Instance Mode.

Creates a new service instance for every method invocation.

12. "Per Session" Instance Mode.

Creates a single service instance for the duration of a client session.

13. "Singleton" Instance Mode.

Uses a single service instance for all clients.

14. What is a Client?

A client is an application or program that consumes the services provided by a WCF service.

15. How WCF Works.

WCF uses endpoints for communication. It supports various protocols, message patterns, and security mechanisms, and it provides different instance modes.

16. ASMX Web Services vs. WCF.

Feature ASMX WCF
Protocol HTTP only (typically SOAP) Multiple protocols (HTTP, TCP, etc.)
Hosting IIS only Various hosting options
Security Limited security options Comprehensive security model
Serialization XmlSerializer DataContractSerializer

17. Types of WCF Contracts.

  • Service Contract: Defines operations exposed by the service.
  • Data Contract: Defines the data types used by the service.
  • Fault Contract: Defines exceptions that can be returned by operations.
  • Message Contract: Defines the message structure.

18. Hosting a WCF Service.

A WCF service requires a host (a process managing its lifecycle):

  • Self-hosting (in a managed application): Console application, Windows Forms application, Windows Service.
  • Web hosting: IIS (Internet Information Services) or WAS (Windows Process Activation Service).

19. Isolation Levels in WCF.

Isolation levels control how transactions interact, ensuring data consistency:

  • Read Uncommitted: Lowest isolation level; allows reading uncommitted data (dirty reads).
  • Read Committed: Prevents dirty reads (default).
  • Repeatable Read: Prevents non-repeatable reads and phantom reads.
  • Serializable: Highest isolation level; prevents all concurrency issues.
  • Snapshot: Uses database snapshots for concurrency control.

20. Address Formats for WCF Bindings.

(This section lists the address format syntax for different bindings—TCP, HTTP, MSMQ.)

21. WCF RIA Services.

WCF RIA Services was a framework for building n-tier Rich Internet Applications (RIAs) using technologies like Silverlight or AJAX. It is now largely outdated.

22. Generating WCF Proxies.

Generate proxies using Visual Studio's "Add Service Reference" or the svcutil.exe command-line tool.

23. What is Binding in WCF?

A binding defines the communication details between a client and a WCF service (protocol, encoding, security).

24. Communication Modes in WCF.

  • One-way: The client sends a request and doesn't wait for a response.
  • Request-reply: The client sends a request and waits for a response.
  • Duplex: Both client and server can send messages independently (requires a callback contract).

25. Request-Reply Mode.

The client sends a request and waits for a response from the service. A timeout might be specified to handle cases where a response is not received.

26. Types of WCF Bindings.

(This section would list the different binding types available in WCF.)

27. Transport Schemas Supported by WCF.

  • HTTP
  • TCP
  • Named Pipes
  • MSMQ (Message Queuing)

28. Ways of Hosting a WCF Service.

  • IIS (Internet Information Services)
  • Self-hosting (within a custom application)
  • WAS (Windows Activation Service)

29. Duplex Contracts.

Duplex contracts enable two-way communication where both the client and the server can independently send messages to each other.

30. Data Contracts.

Data contracts define the data types used in WCF messages. The [DataContract] and [DataMember] attributes are used to specify which types and members should be serialized into the message.

31. DataContractSerializer.

DataContractSerializer is a high-performance serializer used by WCF for serializing data contracts.

32. Enabling Metadata.

Enable metadata in the WCF service's configuration (web.config) using the `` element.

33. Bindings Used for Metadata.

(This would list bindings like `mexHttpBinding`, `mexHttpsBinding`, etc.)

34. Testing WCF Services Without a Client App.

Use the wcftestclient.exe tool.

35. Transport and Message Reliability.

Transport reliability ensures reliable message delivery at the transport level. Message reliability ensures reliable message delivery regardless of the underlying transport.

36. Transport Reliability in WCF.

Transport reliability is generally provided by protocols like TCP, which guarantees message delivery and ordering.

37. SOA (Service-Oriented Architecture).

SOA is an architectural style where applications are built as a collection of services that communicate with each other.

38. receiveTimeout Property.

Specifies the maximum time a service waits to receive a message.

39. Generating Proxies with svcutil.

(This section would detail the command-line usage of the `svcutil` tool.)

40. RPC vs. Message Style.

Style Description
RPC (Remote Procedure Call) Similar to a local procedure call
Message More control over message structure

41. One-Way Mode.

In one-way mode, the client doesn't wait for a response from the server.

42. Callback Mode.

In callback mode, the service can send messages back to the client (requires a duplex contract).

43. Transaction Managers in WCF.

  • Lightweight transaction manager
  • WS-AtomicTransaction
  • OLE transaction manager

44. MEPs (Message Exchange Patterns).

  • Datagram
  • Request-reply
  • Duplex

45. Address Format in WCF.

(This section would provide a description of the syntax and structure used for specifying the address of endpoints in WCF.)

46. Throttling in WCF.

Throttling limits the number of concurrent calls and sessions to a WCF service, improving performance and resource management.

47. maxConcurrentCalls.

Limits the number of concurrent calls to the service.

48. KnownType Attribute.

The KnownType attribute is used when serializing objects to ensure that the serializer knows about all the types within a class hierarchy. This is important when you have a class that contains other classes as properties.

49. KnownType Example.

Code Example (C#)

[KnownType(typeof(TestClassCar))]
[KnownType(typeof(TestClassTruck))]
[DataContract]
public class TestClassVehicle { }