WCF FAQs – Part 1

What is WCF?
Windows Communication Foundation (WCF) is an SDK for developing and deploying services on Windows. WCF provides a runtime environment for services, enabling you to expose CLR types as services, and to consume other services as CLR types. WCF is part of .NET 3.0 and requires .NET 2.0, so it can only run on systems that support it.

What are three major points in WCF? / What is ABC of WCF?
Address – Specifies the location of the service which will be like http://Myserver/MyService. Clients will use this location to communicate with WCF service.
Binding – Specifies how Client and Server will communicate in term of transport and encoding and protocols.
Contract – Specifies the interface between client and the server. It’s a simple interface with some attribute.

Difference between WCF and Web services?
Web Services can be accessed only over HTTP
Web Services works in stateless environment
WCF is flexible because its services can be hosted in different types of applications.

What are the various ways of hosting a WCF service?
The following lists several common scenarios for hosting WCF services:
* WAS (Windows Activation Service)
* Self-hosting
* Managed Windows Service

What are the advantages of hosting WCF Services in IIS as compared to self-hosting?
There are two main advantages of using IIS over self-hosting:-
Automatic activation – IIS provides automatic activation that means the service is not necessary to be running in advance. When any message is received by the service it then launches and fulfills the request. But in case of self hosting the service should always be running.
Process recycling – If IIS finds that a service is not healthy that means if it has memory leaks etc, IIS recycles the process. For every browser instance, a worker process is spawned and the request is serviced. When the browser disconnects, the worker process stops and you loose all information. IIS also restarts the worker process. By default, the worker process is recycled at around 120 minutes. By restarting the worker process it ensures any bad code or memory leak do not cause issue to the whole system.
In case of self-hosting both the above features, you will need to code yourself.

What was the code name for WCF?
The code name of WCF was Indigo. WCF is a unification of .NET framework communication technologies which unites the following technologies-

NET remoting
Web services

What are the main components of WCF?
The main components of WCF are-

1. Service class
2. Hosting environment
3. End point

What is contracts in WCF?
In WCF, all services expose contracts. The contract is a platform-neutral and standard way of describing what the service does.

WCF defines four types of contracts.

1. Service contracts : Describe which operations the client can perform on the service.

2. Data contracts : Define which data types are passed to and from the service. WCF defines implicit contracts for built-in types such as int and string, but we can easily define explicit opt-in data contracts for custom types.

3. Fault contracts : Define which errors are raised by the service, and how the service handles and propagates errors to its clients.

4. Message contracts : Allow the service to interact directly with messages. Message contracts can be typed or untyped, and are useful in interoperability cases and when there is an existing message format we have to comply with.

What is binding and how many types of bindings are there in WCF?
A binding defines how an endpoint communicates to the world. A binding defines the transport (such as HTTP or TCP) and the encoding being used (such as text or binary).

A binding can contain binding elements that specify details like the security mechanisms used to secure messages, or the message pattern used by an endpoint.

WCF supports nine types of bindings.

1. Basic binding :

Offered by the BasicHttpBinding class, this is designed to expose a WCF service as a legacy ASMX web service, so that old clients can work with new services. When used by the client, this binding enables new WCF clients to work with old ASMX services.

2. TCP binding :
Offered by the NetTcpBinding class, this uses TCP for cross-machine communication on the intranet. It supports a variety of features, including reliability, transactions, and security, and is optimized for WCF-to-WCF communication. As a result, it requires both the client and the service to use WCF.

3. Peer network binding :
Offered by the NetPeerTcpBinding class, this uses peer networking as a transport. The peer network-enabled client and services all subscribe to the same grid and broadcast messages to it.

4. IPC binding :
Offered by the NetNamedPipeBinding class, this uses named pipes as a transport for same-machine communication. It is the most secure binding since it cannot accept calls from outside the machine and it supports a variety of features similar to the TCP binding.

5. Web Service (WS) binding :
Offered by the WSHttpBinding class, this uses HTTP or HTTPS for transport, and is designed to offer a variety of features such as reliability, transactions, and security over the Internet.

6. Federated WS binding :
Offered by the WSFederationHttpBinding class, this is a specialization of the WS binding, offering support for federated security.

7. Duplex WS binding :
Offered by the WSDualHttpBinding class, this is similar to the WS binding except it also supports bidirectional communication from the service to the client.

8. MSMQ binding :
Offered by the NetMsmqBinding class, this uses MSMQ for transport and is designed to offer support for disconnected queued calls.

9. MSMQ integration binding :
Offered by the MsmqIntegrationBinding class, this converts WCF messages to and from MSMQ messages, and is designed to interoperate with legacy MSMQ clients.

What are different isolation levels provided in WCF?
The different isolation levels:

1. READ UNCOMMITTED: – An uncommitted transaction can be read. This transaction can be rolled back later.

2. READ COMMITTED :- Will not read data of a transaction that has not been committed yet

3. REPEATABLE READ: – Locks placed on all data and another transaction cannot read.

4. SERIALIZABLE:- Does not allow other transactions to insert or update data until the transaction is complete.

Explain transactions in WCF.
Transactions in WCF allow several components to concurrently participate in an operation. Transactions are a group of operations that are atomic, consistent, isolated and durable. WCF has features that allow distributed transactions. Application config file can be used for setting transaction timeouts.

What is the proxy for WCF Service?
A proxy is a class by which a service client can Interact with the service. By the use of proxy in the client application we are able to call the different methods exposed by the service.

How can we create Proxy for the WCF Service?
We can create proxy using the tool svcutil.exe after creating the service. We can use the following command at command line.
svcutil.exe *.wsdl *.xsd /language:C# /out:SampleProxy.cs /config:app.config

What is service and client in perspective of data communication?
A service is a unit of functionality exposed to the world.
The client of a service is merely the party consuming the service.

What is endpoint in WCF?
Every service must have Address that defines where the service resides, Contract that defines what the service does and a Binding that defines how to communicate with the service. In WCF the relationship between Address, Contract and Binding is called Endpoint. The Endpoint is the fusion of Address, Contract and Binding.

What are ends, contract, address, and bindings?
The above terminologies are the core on which SOA stands. Every service must expose one or more ends by which the service can be available to the client. End consists of three important things where, what and how:-
* Contract (What)
Contract is an agreement between two or more parties. It defines the protocol how client should communicate with your service. Technically, it describes parameters and return values for a method.
* Address (Where)
An Address indicates where we can find this service. Address is a URL, which points to the location of the service.
* Binding (How)
Bindings determine how this end can be accessed. It determines how communications is done. For instance, you expose your service, which can be accessed using SOAP over HTTP or BINARY over TCP. So for each of these communications medium two bindings will be created.

What is Throttling in the context of WCF Service?
Throttling in the context of WCF Service means limiting the WCF service properties like-
* maximum concurrent calls or
* maximum concurrentInstances or
* maximum concurrentsessions
This can be achieved using web.config or c# code.

How to set Throttling properties of WCF maxConcurrentCalls, maxConcurrentInstances and maxConcurrentSessions in code?
We can set Throttling properties of WCF maxConcurrentCalls maxConcurrentInstances maxConcurrentSessions in code as well as in Web.config.
Below is the code to set these behaviours in code-

ServiceHost samplehost = new ServiceHost(typeof(sampleService));
ServiceThrottlingBehavior samplethrottle = host.Description.Behaviors.Find();
if (samplethrottle == null)
   samplethrottle = new ServiceThrottlingBehavior();
   samplethrottle.MaxConcurrentCalls = 25;
   samplethrottle.MaxConcurrentSessions = 10;
   samplethrottle.MaxConcurrentInstances = 10;

What is Kerberos Protocol?
Kerberos Protocol is a protocol that defines how clients interact with a network authentication service.
Kerberos tickets represent the clients’ network credentials.

What is the default value for maxWorkerThreads for ASP.NET process dual core computer?
The default value is 40 for maxWorkerThreads for ASP.NET process dual core computer.

How to create a Duplex contract in WCF or Windows Communication Foundation service?
To create a Duplex contract in WCF or Windows Communication Foundation service; Just create two interfaces, a service contract interface and a callback contract Interface. The callback contract defines the operations that the service can call on the client endpoint.

This entry was posted in Interview Questions, WCF. Bookmark the permalink.

Leave a Reply