22 Essential WCF Interview Questions Your Team Lead Can't Answer
Tags: career, interview, net
Published: 2019-09-23 02:23:35

---
title: 22 Essential WCF Interview Questions Your Team Lead Can't Answer
published: true
description: 22 Essential WCF Interview Questions Your Team Lead Can't Answer
tags: #career #interview #net
canonical_url: https://www.fullstack.cafe/blog/wcf-interview-questions
cover_image: https://images.pexels.com/photos/2409681/pexels-photo-2409681.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500
---
Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Regardless of it’s age, WCF it is still a framework that can allow you to build really complex solutions, control all aspects of your data flow and stays an essential skill of any experienced .NET Developer.

> Originally published on [Fullstack.Cafe - Never Fail Tech Interview Again](https://www.fullstack.Cafe)

### Q1: What is WCF?
> Topic: **WCF**<br/>Difficulty: ⭐

**Windows Communication Foundation (WCF)** is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application. An endpoint can be a client of a service that requests data from a service endpoint. The messages can be as simple as a single character or word sent as XML, or as complex as a stream of binary data.

🔗 **Source:** [docs.microsoft.com](https://docs.microsoft.com/en-us/dotnet/framework/wcf/whats-wcf)
### Q2: Could you name basic WCF service components?
> Topic: **WCF**<br/>Difficulty: ⭐⭐

Have a look at this mindmap to navigate yourself through WCF service components:
<div class="text-center">
<img src="http://1.bp.blogspot.com/_ilf9yT58u-k/R5dVNShe9nI/AAAAAAAAACM/jvIaKFVrU8g/s1600/Windows+Communication+Foundation+Mindmap.png" class="img-fluid" style="max-width: 900px"/>
</div>


🔗 **Source:** [codeproject.com](https://www.codeproject.com/Articles/426776/WCF-Top-Interview-Questions)
### Q3: What is a service contract in WCF?
> Topic: **WCF**<br/>Difficulty: ⭐⭐

A **service contract** defines the operations which are exposed by the service to the outside world. A service contract is the interface of the WCF service and it tells the outside world what the service can do. It may have service-level settings, such as the name of the service and namespace for the service.

```csharp
[ServiceContract]
interface IMyContract { 
    [OperationContract]
	string MyMethod();
}

class MyService: IMyContract {
	public string MyMethod() {
		return "Hello World";
	}
}
```

🔗 **Source:** [dotnettricks.com](https://www.dotnettricks.com/learn/wcf/understanding-different-types-of-wcf-contracts)
### Q4: Explain what is SOA?
> Topic: **WCF**<br/>Difficulty: ⭐⭐

**SOA** stands for **service-oriented architecture. Service Oriented Architecture is an architectural approach in software development where the application is organized as "Services". Services are a group of methods that contain the business logic to connect a DB or other services. For instance you go to a hotel and order food. Your order first goes to the counter and then it goes to the kitchen where the food is prepared and finally the waiter serves the food. 

**Some important characteristics of Service Oriented Architecture**

*   SOA services should be **independent** of other services.  Altering a service should not affect the client calling the service.  
*   Services should be **self-contained. **  Services should be able to **define themselves** (in the Web Service Description Language (WSDL)).  It should be able to tell the client what all of the operations it does, what are all the data types it uses and what kind of value it will return.

🔗 **Source:** [c-sharpcorner.com](https://www.c-sharpcorner.com/UploadFile/8ef97c/wcf-interview-questions-and-answers/)
### Q5: What are the features and advantage of WCF?
> Topic: **WCF**<br/>Difficulty: ⭐⭐

Features of WCF**  
  
Windows Communication Foundation (WCF) is a secure, reliable, and scalable messaging platform for the .NET Framework 3.0,

*   Service Orientation
*   Interoperability
*   Multiple Message Patterns
*   Service Metadata
*   Data Contracts
*   Security
*   Multiple Transports and Encodings
*   Reliable and Queued Messages
*   Durable Messages
*   Transactions
*   AJAX and REST Support
*   Extensibility

**Advantages of WCF**:

1.  Service Oriented
2.  Location Independent
3.  Language Independent
4.  Platform Independent
5.  Support Multiple operation
6.  WCF can maintain transaction like COM+ Does
7.  It can maintain state
8.  It can control concurrency
9.  It can be hosted on IIS, WAS, Self hosting, Windows services.

🔗 **Source:** [docs.microsoft.com](https://docs.microsoft.com/en-us/dotnet/framework/wcf/whats-wcf)
### Q6: What is transport in WCF?
> Topic: **WCF**<br/>Difficulty: ⭐⭐⭐

The WCF programming model separates endpoint operations (as expressed in a service contract) from the transport mechanism that connects two endpoints. This gives you the flexibility to decide how to expose your services to the network. The transport layer is at the lowest level of the channel stack. A transport sends or receives the serialized form of a message to or from another application. The main transports used in Windows Communication Foundation (WCF) are:
* HTTP, 
* HTTPS, 
* TCP
* named pipes. 

🔗 **Source:** [weblogs.asp.net](https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/transports)
### Q7: What is WCF Binding and how many of them do you know?
> Topic: **WCF**<br/>Difficulty: ⭐⭐⭐

**Bindings** specify how a Windows Communication Foundation (WCF) service endpoint communicates with other endpoints. At its most basic, a binding must specify the _transport_ (for example, HTTP or TCP) to use. You can also set other characteristics, such as security and transaction support, through bindings.

WCF provides nine built-in bindings:

* **BasicHttpBinding**: Basic web service communication. Exposes WCF services as legacy ASMX web services. Used for interoperability. No security by default.
* **WSHttpBinding**: Web services with WS-* support. Supports transactions and reliable messaging.
* **WSDualHttpBinding**: Web services with duplex contract and transaction support.
* **WSFederationHttpBinding**: Web services with federated security. Supports transactions.
* **MsmqIntegrationBinding**: Communication directly with MSMQ applications. Supports transactions.
* **NetMsmqBinding**: Communication between WCF applications by using queuing. Supports transactions.
* **NetNamedPipeBinding**: Communication between WCF applications on same computer. Supports duplex contracts and transactions.
* **NetPeerTcpBinding**: Communication between computers across peer-to-peer services. Supports duplex contracts.
* **NetTcpBinding**: Communication between WCF applications across computers. Supports duplex contracts and transactions.

🔗 **Source:** [weblogs.asp.net](https://weblogs.asp.net/spano/choosing-the-right-wcf-binding)
### Q8: What are the Possible Ways of Hosting a WCF Service? 
> Topic: **WCF**<br/>Difficulty: ⭐⭐⭐

For a **Windows Communication Foundation** service to host, we need at least a managed process, a `ServiceHost` instance and an `Endpoint` configured. Possible approaches for hosting a service are:

1.  Hosting in a Managed Application/Self Hosting
    1.  Console Application
    2.  Windows Application
    3.  Windows Service
2.  Hosting on Web Server
    1.  IIS 6.0 (ASP.NET Application supports only HTTP)
    2.  Windows Process Activation Service (WAS) i.e. IIS 7.0 supports HTTP, TCP, NamedPipes, MSMQ.

🔗 **Source:** [codeproject.com](https://www.codeproject.com/Articles/426776/WCF-Top-Interview-Questions)
### Q9: What is Message Contract in WCF?
> Topic: **WCF**<br/>Difficulty: ⭐⭐⭐

Sometimes complete control over the structure of a SOAP message is just as important as control over its contents (that defined by Data Contracts). This is especially true when interoperability is important or to specifically control security issues at the level of the message or message part. In these cases, you can create a _message contract_ that enables you to specify the structure of the precise SOAP message required.

🔗 **Source:** [c-sharpcorner.com](https://www.c-sharpcorner.com/UploadFile/8ef97c/wcf-interview-questions-and-answers/)
### Q10: What is an Operation Contract in WCF?
> Topic: **WCF**<br/>Difficulty: ⭐⭐⭐

An **operation contract** is defined within a service contract. It defines the parameters and return type of an operation. An operation contract can also defines operation-level settings, like as the transaction flow of the operation, the directions of the operation (one-way, two-way, or both ways), and fault contract of the operation.

```csharp
[ServiceContract]
interface IMyContract { 
    [FaultContract(typeof(MyFaultContract))]
    [OperationContract]
	string MyMethod();
}
```

🔗 **Source:** [dotnettricks.com](https://www.dotnettricks.com/learn/wcf/understanding-different-types-of-wcf-contracts)
### Q11: Name some different types of contracts in WCF
> Topic: **WCF**<br/>Difficulty: ⭐⭐⭐

WCF contract specifies the service and its operations. WCF has five types of contracts: 
* service contract, 
* operation contract, 
* data contract, 
* message contract
* fault contract.

🔗 **Source:** [dotnettricks.com](https://www.dotnettricks.com/learn/wcf/understanding-different-types-of-wcf-contracts)
### Q12: Explain the difference between WCF vs ASP.NET Web API?
> Topic: **WCF**<br/>Difficulty: ⭐⭐⭐

In the scenarios listed below you should go for WCF:

* If you need to send data on protocols like TCP, MSMQ or MIME
* If the consuming client just knows how to consume SOAP messages
WEB API is a framework for developing RESTful/HTTP services.

Consider:

|WCF|ASP.NET Web API|
|--- |--- |
|Enables building services that support multiple transport protocols (HTTP, TCP, UDP, and custom transports) and allows switching between them.|HTTP only. First-class programming model for HTTP. More suitable for access from various browsers, mobile devices etc enabling wide reach.|
|Enables building services that support multiple encodings (Text, MTOM, and Binary) of the same message type and allows switching between them.|Enables building Web APIs that support wide variety of media types including XML, JSON etc.|
|Supports building services with WS-* standards like Reliable Messaging, Transactions, Message Security.|Uses basic protocol and formats such as HTTP, WebSockets, SSL, JSON, and XML. There is no support for higher level protocols such as Reliable Messaging or Transactions.|
|Supports Request-Reply, One Way, and Duplex message exchange patterns.|HTTP is request/response but additional patterns can be supported through SignalR and WebSockets integration.|
|WCF SOAP services can be described in WSDL allowing automated tools to generate client proxies even for services with complex schemas.|There is a variety of ways to describe a Web API ranging from auto-generated HTML help page describing snippets to structured metadata for OData integrated APIs.|
|Ships with the .NET framework.|Ships with .NET framework but is open-source and is also available out-of-band as independent download.|

🔗 **Source:** [stackoverflow.com](https://stackoverflow.com/questions/9348639/wcf-vs-asp-net-web-api)
### Q13: Why we need Streaming?
> Topic: **WCF**<br/>Difficulty: ⭐⭐⭐

When you have a large amount of data to transfer, the streaming transfer mode in WCF is a feasible alternative to the default behavior of buffering and processing messages in memory in their entirety.

In WCF any receiving message is delivered only once the entire message has been received. What I mean here is that first message is buffered at the receiving side and once it is fully received it gets delivered to the receiving end. The main problem with this approach is that the receiver end is unresponsive while the message is getting buffered. So default way of message handling in WCF is ok for small size messages but for the large size messages, this approach is not good. So to overcome this problem Streaming in WCF come into action.

🔗 **Source:** [c-sharpcorner.com](https://www.c-sharpcorner.com/UploadFile/dhananjaycoder/streaming-in-wcf/)
### Q14: What is interoperability and how is it achieved with WCF services?
> Topic: **WCF**<br/>Difficulty: ⭐⭐⭐⭐

**Interoperability** is the ability to communicate with other platforms through standard protocols (such as SOAP). One of the major benefits of SOAP is that it is platform independent. 

WCF is designed and built to interoperate with web services that support the Web Services Specification,
known as the WS-* specifications. As such, WCF comes with three system-provided bindings that facilitate
interoperability. These bindings are shown in the following list:
* **BasicHttpBinding**: WCF services can use this binding to configure and expose endpoints. These
endpoints in turn can communicate with *.asmx-based web services as well as clients and services
that comply with the WS-I Basic Profile 1.1.
* **WsHttpBinding**: Supports distributed transactions as well as secure and reliable sessions.
* **WsDualHttpBinding**: Support for duplex communication and communication via SOAP
intermediaries.

🔗 **Source:** [codeproject.com](https://www.codeproject.com/Articles/426776/WCF-Top-Interview-Questions)
### Q15: When would you use Duplex WCF service?
> Topic: **WCF**<br/>Difficulty: ⭐⭐⭐⭐

You need duplex if you want to implement callback pattern. Callback means that client does not know when some event happens in server. If you do not know when event happens you have two options to implement:

* Polling - send requests every X minutes to check if event happened. Server should either return event details (if it happened) or return flag saying that you need to continue calling. Server also can return recommended timeout in advanced scenarios.
* Callback - client sends some form of description what server should do if event happened. This may be pointer to function in C, delegate in .NET or endpoint schema in WCF. Server remembers that info and makes call from their side when time came.
As you can see duplex/callback means that at some point server works as client (initiates communication) and this is a big game change.

WCF duplex communications may require special network configuration because in many cases network allows you to call external services (you work as client) but forbids external resources to call you (external service works as client). This is implemented for security purposes.

🔗 **Source:** [medium.com](https://medium.com/@mirzafarrukh13/wcf-message-exchange-pattern-bd8db187af04)
### Q16: Will it make any difference if I change the operation contract of methods having no return value by [OperationContract(IsOneWay=true)]?
> Topic: **WCF**<br/>Difficulty: ⭐⭐⭐⭐

Yes it will - and more importantly **boost scalability too**. Client is released as soon as call is taken up at the server and client does not have to wait until processing finishes. This helps the resources at both client and server to be released as soon as possible.



🔗 **Source:** [stackoverflow.com](https://stackoverflow.com/questions/7809947/benefits-of-using-oneway-over-a-response-request-contract-in-wcf-for-void-method)
### Q17: Explain Binary vs MTOM vs Streaming in WCF?
> Topic: **WCF**<br/>Difficulty: ⭐⭐⭐⭐⭐

* **MTOM** is a standard that uses multi-part mime-encoded messages to send portions of the message that are large and would be too expensive to base64 encode as pure binary. The SOAP message itself is sent as the initial part of the message and contains references to the binary parts which a web service software stack like WCF can then pull back together to create a single representation of the message.
* **Binary** encoding is entirely proprietary to WCF and really doesn't just have to do with large messages. It presents a binary representation of the XML Infoset which is far more compact across the wire and faster to parse than text based formats. If you happen to be sending large binary chunks of data then it just fits right in with the other bytes that are being sent.
* **Streaming** can be done used with any message format. That's more about when the data is written across the network vs. being buffered entirely in memoery before being presented to the network transport. Smaller messages make more sense to buffer up before sending and larger messages, especially those containing large binary chunks or streams, necessitate being streamed or will exhaust memory resources.

🔗 **Source:** [stackoverflow.com](https://stackoverflow.com/questions/6846238/send-binary-data-via-wcf-binary-vs-mtom-encoding)
### Q18: What is the difference between hosting WCF service on IIS, Windows Service and self-hosted app?
> Topic: **WCF**<br/>Difficulty: ⭐⭐⭐⭐⭐

There is no standard answer to this question. IIS provides you with a lot of out-of-the-box features, like app domain reloading, monitoring and so on. This is why you should answer this questions first: do you need all these features or not? If not - windows service can be considered.

Other thing to consider:
* IIS gives you on-demand loading - this can be a plus or a minus. When a request comes in, the ServiceHost is constructed, then the service class being hosted is instantiated, and the request is handled. Nothing needs to be running around the clock. But at the same time, this setup requires more time and effort every time a message comes in, and you as a programmer don't have much control over your service host, really.
* Self-hosting is often times faster, since your ServiceHost is already up and running - but it's up to you to make sure it really is up and running, there's no "on-demand" loading whenever a message comes in - either it's up and can service the request, or not. But you have a lot more control over the service host - when and how it's constructed etc., and you get to pick and define your service addresses as you see fit.

And some information from Microsoft:

|Hosting Environment|Common Scenarios|Key Benefits and Limitations|
|--- |--- |--- |
|Managed Application ("Self-Hosted")| - Console applications used during development. - Rich WinForm and WPF client applications accessing services.|-   Flexible.-   Easy to deploy.-   Not an enterprise solution for services.|
|Windows Services (formerly known as NT services)|-   A long-running WCF service hosted outside of IIS.|-   Service process lifetime controlled by the operating system, not message-activated.-   Supported by all versions of Windows.-   Secure environment.|
|IIS 5.1, IIS 6.0|-   Running a WCF service side-by-side with ASP.NET content on the Internet using the HTTP protocol.|-   Process recycling.-   Idle shutdown.-   Process health monitoring.-   Message-based activation.-   HTTP only.|
|Windows Process Activation Service (WAS)|-   Running a WCF service without installing IIS on the Internet using various transport protocols.|-   IIS is not required.-   Process recycling.-   Idle shutdown.-   Process health monitoring.-   Message-based activation.-   Works with HTTP, TCP, named pipes, and MSMQ.|
|IIS 7.0|-   Running a WCF service with ASP.NET content.-   Running a WCF service on the Internet using various transport protocols.|-   WAS benefits.-   Integrated with ASP.NET and IIS content.|


🔗 **Source:** [codeproject.com](https://www.codeproject.com/Articles/426776/WCF-Top-Interview-Questions)
### Q19: Could we use WSHttpBinding with Request-CallBack (also called Duplex) exchange pattern?
> Topic: **WCF**<br/>Difficulty: ⭐⭐⭐⭐⭐

HTTP protocol does not support duplex communication — responses are valid only for each request, so the answer is no. This prevents HTTP-based bindings such as `BasicHttpBinding` and `WSHttpBinding` from supporting duplex. To address this limitation, WCF provides `WSDualHttpBinding`. This binding uses composite duplex communication, which means two communication channels are created to support calls in both directions.

🔗 **Source:** [medium.com](https://medium.com/@mirzafarrukh13/wcf-message-exchange-pattern-bd8db187af04)
### Q20: What is the main difference between Request-Response and Duplex in WCF Message Exchange Pattern?
> Topic: **WCF**<br/>Difficulty: ⭐⭐⭐⭐⭐

The main difference is that, after the client establishes a channel to the service, the service can call the client independently at any time. In Request-Response the service only communicates back after receiving a Request from the client. So by using duplex you receive an event-like behavior from the client perspective. Obviously, such enhancement requires a Session to be maintained (instance mode PerSession on the service). 

🔗 **Source:** [stackoverflow.com](https://stackoverflow.com/questions/13671473/request-response-vs-duplex-wcf-message-exchange-pattern)
### Q21: Should I use WCF or raw sockets?
> Topic: **WCF**<br/>Difficulty: ⭐⭐⭐⭐⭐

Sockets are very low level. Today I would never go down to such a low level as sockets unless you really have to. Working with high level abstractions is way more productive and creative. The big advantage of Remoting or WCF is that you can pass objects between server and client and call methods on them on each side. Also be aware that the performance of Net.tcp communication over WCF is much worse than plain socket communication. It is because WCF simplifies a lot of things but those simplification and generalizations slows processing. So it depends. 

🔗 **Source:** [stackoverflow.com](https://stackoverflow.com/questions/3325847/should-i-use-wcf-or-raw-sockets)
### Q22: What replaces WCF in .Net Core?
> Topic: **WCF**<br/>Difficulty: ⭐⭐⭐⭐⭐

WCF client-side is already supported on.NET Core. WCF server-side is not supported in .NET Core since it's a Windows specific technology while .NET Core is supposed to be cross-platform. WCF won't likely be ported to .NET Core, because most of the code-base depends on Windows internal libraries. There are some alternatives that you could use for the server-side thought:
1. **IpcServiceFramework** - A .NET Core lightweight inter-process communication framework allowing invoking a service via named pipeline and/or TCP (in a similar way as WCF, which is currently unavailable for .NET Core). Secure communication over SSL is also supported.
2. **gRPC** - a high performance, open source RPC framework initially developed by Google. The framework is based on a client-server model of remote procedure calls. A client application can directly call methods on a server application as if it was a local object.
3. **Core WCF** - Core WCF is a port of Windows Communication Framework (WCF) to .NET Core. The goal of this project is to enable existing WCF projects to move to .NET Core.

🔗 **Source:** [stackoverflow.com](https://stackoverflow.com/questions/48522849/what-replaces-wcf-in-net-core)

> *Thanks 🙌 for reading and good luck on your interview!* <br/>*Please share this article with your fellow devs if you like it!* <br/>*Check more FullStack Interview Questions & Answers on 👉 [www.fullstack.cafe](https://www.fullstack.cafe)*