Javatpoint Logo
Javatpoint Logo

WCF Interview Questions

There is given frequently asked WCF interview questions and answers that have been asked in many companies. Let's see the list of top WCF interview questions.

1) What is WCF?

WCF stands for Windows Communication Foundation. It is a framework which is used for building, configuring and deploying interoperable distributed services. 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. It provides a facility to write more secure, flexible services without any code change. It also provides built-in support for logging. It facilitates you to enable/disable logging using configuration.

Its code name is "Indigo".


2) What are the WCF service endpoints?

WCF service endpoint has three basic elements: address, binding, and contract.

Address: It defines the address of the URL that identifies the location of the service and specifies the location where messages are received. It is specified as a Uniform Resource Identifier (URI). The URI schema part names the transport mechanism to use to reach the address, such as HTTP and TCP. The hierarchical part of the URI contains a unique location whose format is dependent on the transport mechanism.

The endpoint address enables you to create unique endpoint addresses for each endpoint in service or, under certain conditions, to share an address across endpoints. The following example shows an address using the HTTPS protocol with a non-default port:

https://cohowinery:8005/ServiceModelSamples/CalculatorService

Binding: It defines how the service can be accessed, how an endpoint communicates to the world. It is constructed of a set of components called binding elements that "stack" one on top of the other to create the communication infrastructure. At the very least, 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.

Contract: It defines what is exposed by the service. Ties together multiple related operations into a single functional unit. The contract can define service-level settings, such as the namespace of the service, a corresponding callback contract, and other such settings. In most cases, the contract is defined by creating an interface in the programming language of your choice and applying the ServiceContractAttribute attribute to the interface. The actual service code results by implementing the interface.

Operation contract

An operation contract defines the parameters and returns type of operation. When creating an interface that defines the service contract, you signify an operation contract by applying the OperationContractAttribute attribute to each method definition that is part of the contract. The operations can be modeled as taking a single message and returning a single message, or as taking a set of types and returning a type. In the latter case, the system will determine the format for the messages that need to be exchanged for that operation.

Message contract

Describes the format of a message. For example, it declares whether message elements should go in headers versus the body, what level of security should be applied to what elements of the message, and so on.

Fault contract

Can be associated with a service operation to denote errors that can be returned to the caller. An operation can have zero or more faults associated with it. These errors are SOAP faults that are modeled as exceptions in the programming model.

Data contract

The descriptions in metadata of the data type that a service uses. This enables others to interoperate with the service. The data types can be used in any part of a message, for example, as parameters or return types. If the service is using only simple types, there is no need to use data contracts explicitly.


3) What are the essential components used in WCF?

A list of essential components used in WCF:

Service class

The service runtime layer contains the behaviors that occur only during the actual operation of the service, that is, the runtime behaviors of the service. Throttling controls how many messages are processed, which can be varied if the demand for the service grows to a preset limit.

Endpoint

WCF Service is a program that exposes a collection of the endpoints. Each Endpoint is a portal for communicating with the world. All the WCF communications are taken place through the endpoint. An endpoint consists of three components.

Hosting Environment

A service must be hosted in some process. A host is an application that controls the lifetime of the service. Services can be self-hosted or managed by an existing hosting process.


4) What is the "Address" property of endpoint in WCF?

The "Address" property is the part of endpoint defined in service level. This property is used to specify the location where the service is located.


5) What is the "Binding" property of endpoint in WCF?

The "Binding" property is the part of endpoint defined in service level. This property is used to specify the type protocols, encodings, and transport.

These all factors are decided by both the communicating parties.


6) What is the "Contract" property of endpoint in WCF?

The "Contract" property is just an interface between the client and server where client and server communicate with each other. Contracts are used to specify operations available.


7) What is the service?

A service is a set of functionality exposed to the world. Service orientation (SO) is an abstract set of principles and best practices for building service-oriented applications.


8) What is service proxy in WCF?

WCF Proxies are used to communicate between client and server. The communication takes place by exchanging the messages in the form of requests and responses. It will have the details like Service Path, Protocol details and so on.


9) What is "Service Contracts" in WCF?

The Service Contracts attribute is used at the service level for WCF service. It provides the list of operations that can be performed from that service.

Service Contracts can be defined as:

[ServiceContract]


10) What are the different instance modes in WCF?

A list of instance modes in WCF:

  • Per Call
  • Singleton
  • Per Session

11) What is "Per Call" instance mode in WCF?

When a request has made to service, it creates a new instance of service for each method call and this will be disposed of once the response goes to the client. This whole process is known as per call instance mode.


12) What is "Per Session" instance mode in WCF?

Per session instance mode creates a logical session between service and client and it will be maintained till the end of the session. When client requests from service the session will be created and it is dedicated to the instance for that client and it will be going to the end when client session ends.


13) What is "Singleton" instance mode in WCF?

In "Singleton" mode all the clients are connected to the single instance of the service and when service configured for "Singleton" mode, an instance will be created when service is hosted and it will be disposed of once it shuts down.


14) What do you mean by client?

The client of a service is the program unit consuming its functionality. A client can be anything like a Console application, Windows form, WPF or Silverlight class or ASP.Net page etc.


15) How do WCF works?

WCF follows the model "Software as a Service". In this model all units of functionality are defined as services and for communication, each point is a portal or connection either with the client or other services. It is a program that exposes a collection of endpoints.


16) What is the difference between ASMX web services and WCF?

The main difference between WCF and ASMX web service is that ASMX is designed to send and receive messages using SOAP over HTTP only while WCF facilitates you to send and receive messages using any format over any transport protocol.

ASMX web services can be hosted only in IIS while WCF service has all the following hosting options:

  • IIS
  • WAS (Windows Process Activation Services)
  • Console Application
  • Windows NT Services
  • WCF provided Host
  • ASMX web services support is limited to HTTP while WCF supports HTTP, TCP, MSMQ, NamedPipes.
  • ASMX Security is limited. Normally authentication and authorization are done using IIS and ASP.NET security configuration and transport layer security. For message layer security, WSE can be used.
  • WCF provides a consistent security programming model for any protocol and it supports many of the same capabilities as IIS and WS-* security protocols, additionally, it provides support for claims-based authorization that provides finer-grained control over resources than role-based security. WCF security is consistent regardless of the host that is used to implement WCF service.
  • Another major difference is that ASMX web services use XmlSerializer for serialization while WCF uses DataContractSerializer which is far better in performance than XmlSerializer.

17) How many types of contract WCF define?

There are four types of contracts that WCF define:

Service Contracts

The ServiceContract attribute maps a CLR interface (or inferred interface, as you will see later on) to a technology-neutral service contract. The ServiceContract attribute exposes a CLR interface (or a class) as a WCF contract, independently of that type's visibility.

Data Contracts

The descriptions in metadata of the data type that a service uses. This enables others to interoperate with the service. The data types can be used in any part of a message, for example, as parameters or return types. If the service is using only simple types, there is no need to use data contracts explicitly.

Fault Contracts

Can be associated with a service operation to denote errors that can be returned to the caller.

Message Contracts

Describes the format of a message. For example, it declares whether message elements should go in headers versus the body, what level of security should be applied to what elements of the message, and so on.


18) What are the requirements for hosting a WCF service?

You need at least a managed process, a ServiceHost instance and an Endpoint configured for hosting a WCF service.

Following are the possible approaches for hosting a service:

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

19) Which are the different isolation levels in WCF?

Following is a list of different isolation levels in WCF:

  • Read Uncommitted: Also known as dirty isolation level. It makes sure that corrupt Data cannot be read. This is the lowest isolation level.
  • Read Committed: It ensures not to read the data that has been changed by any other application and is not yet committed. It is the default level.
  • Repeatable Read: It stops the usage of dirt read and non-repeatable read. It states that data fetched through a query will be locked and will not be updated by any other transaction.
  • Serializable: It does not allow any modification and addition of new data till the transaction is completed. This is considered to be a very restrictive level.
  • Snapshot: It raises an error on modifying a data that has already been changed by any transaction.

20) Give the address format of all the bindings in WCF.

A list of address formats and their respective bindings:

TCF Address Format - net.tcp://local host:portnumber

HTTP Address Format - http://local host:portnumber

MSMQ Address Format - net.msmq://local host:portnumber


21) Explain the WCF RIA?

WCF RIA is the framework for developing the n-tier application for RIA (Rich Internet App). It is used in Rich Internet Apps like Silverlight, AJAX etc. WCF RIA is used to solve the major problems like Tight Coupling.


22) How would you generate a proxy for WCF?

You can generate proxy by using the following steps:

Using Visual Studio

Using SvcUtil


23) What is binding?

Binding is used to define how an endpoint communicates to the world. It defines the transport such as HTTP or TCP. It can contain binding elements that specify details like the security mechanisms used to secure message patterns used by an endpoint.


24) What are the different modes of communication in WCF?

There are three modes of communication in WCF:

One-Way

In the One-Way operation mode, the client will send a request to the server and does not care whether it is success or failure of service execution. There is no return from the server side, it is one-way communication.

Request-Reply

When as client makes a request to the WCF service and client will wait to get a response from service (till receiveTimeout). After getting the response it will start executing the rest of the statement.

Callback

It is the service to call the client. In which, service will act as client and client will act as service.


25) What is the request-reply mode in WCF?

When a client made a request to a service, it will wait until it gets the response back.

If the response is not received until the given time, it will show an error.

If the client gets the response then next instructions will be executed.


26) How many types of binding are there in WCF?

WCF supports nine types of bindings:

  1. Basic binding
  2. TCP binding
  3. Peer network binding
  4. IPC binding
  5. Web Services binding
  6. Federated Web Service binding
  7. Duplex WS binding
  8. MSMQ binding
  9. MSMQ integration binding

27) What are the transport schemas supported by WCF?

WCF supports the following transport schemas:

  • HTTP
  • TCP
  • PEER network
  • IPC (Inter Process Communication)
  • MSMQ

28) What are the ways of hosting a WCF service?

The ways of hosting a WCF service are:

  • IIS
  • Self-Hosting
  • WAS(Window Activation Service)

29) What are the duplex contracts in WCF?

In WCF, Duplex messaging or call-back is used to communicate with the client. Over different transport system Duplex messaging in WCF is done like TCP, Named pipe and even HTTP. Collectively this is known as duplex contracts in WCF. Basically duplex service contract is a message exchange pattern in which both endpoints can send messages to the other independently. A duplex service, therefore, can send messages back to the client endpoint, providing event-like behavior. Duplex communication occurs when a client connects to a service and provides the service with a channel on which the service can send messages back to the client. Note that the event-like behavior of duplex services only works within a session.


30) What is the usage of DataContracts in WCF?

In WCF, we can communicate with the server from our client through a message. So messages will be going to and fro between server and client. For security purpose, we are serializing the messages sent across the wire.

"[DataContact]" attribute is given at class level to serialize the class by using "[Datamember]" attribute over properties.


31) What is DataContractSerializer?

DataContractSerializer is introduced in .NET 3.0 and WCF uses DataContractSerializer as default one. But now this serializer can be used for other serialization purposes also. For serialization "WriteObject()" method is used.

For example:


32) How would you enable the metadata information of the service?

Following are two ways to enable the metadata for WCF:

For Default Endpoint: <serviceMetadata> tag is used in web.config file without specifying the endpoint.

For Custom Endpoint: <serviceMetadata> tag is used in web.config file with specifying the defined endpoint.


33) Which bindings are used for metadata configuration in WCF?

A list of bindings that are used for metadata:

  • mexHttpBinding
  • mexNamedPipeBinding
  • mexHttpsBinding
  • mexTcpBinding

34) How can you test a WCF application without creating a client application?

There is a tool called - "wcftestclient.exe" used for testing the WCF service without creating a client application. This tool can be opened from visual studio command prompt.


35) What is the transport and message reliability?

Transport reliability: It offers point-to-point guaranteed delivery at the network packet level, as well as guarantees the order of the packets.

Message reliability: It deals with reliability with message level independent of how many packets are required to deliver the message.


36) What is Transport Reliability in WCF?

"Transport Reliability" specifies the guarantee of delivering packets over a network as protocol TCP does. It also maintains the order of the packets as well as delivering of packets.


37) What is SOA?

SOA stands for Service Oriented Architecture. It is a collection of services that determine how the communication is possible between two computing entities to achieve certain business functionality and also how one entity can work on behalf of other entity.


38) What is the usage of "receiveTimeout" property in WCF?

The "recieveTimeout" property is used to get/set the time interval to makes a connection active.


39) How can you generate proxies using Svcutil in WCF?

SvcUtil is a command line utility. You should write the following command to generate proxy:


40) Which styles of models are supported in WCF?

WCF service supports 2 styles of models:

RPC style: In RPC style we can use the serialize types and it provides the feature that is available for local calls.

Message style: In message style WCF allows the message header to be customized and it also allows us to define the security for body and header messages.


41) What is the one-way mode in WCF? Explain.

In WCF one-way mode, a client sends a request to the server but does not wait till the response comes. It does not care if the request is failed or succeeded. The Client will not be blocked in this case until it receives the response.


42) What is Callback mode in WCF? Explain.

Ans: The WCF callback mode is a special type of mode where WCF on the call back calls the method of client and in this scenario WCF service acts as a client and client acts as a service.

This mode is not supported by "HTTPBinding" so "WSDualHttpBinding" is used in this mode.


43) What are the different types of transaction managers supported by WCF?

These are three types of transaction managers supported by WCF:

  1. Light Weight
  2. WS-Atomic Transaction
  3. OLE Transaction

44) What are the MEP in WCF?

MEP stands for Message Exchange Pattern. There are three types of Message Exchange Patterns are allowed:

  1. DataGram
  2. Request and Response
  3. Duplex

45) What is the address format in WCF?

Syntax of address format in WCF:


46) What is Throttling in WCF?

In WCF, "Throttling" is used to limit the sessions or instances to be created at an application level. It is used to boost the performance.


47) What is the usage of "maxConcurrentCalls" in Throttling?

The "maxConcurrentCalls" attribute in throttling is used to limit the total number of calls which are going to the service instances. Its default value is 16.


48) What is "Know Types" in WCF?

The KnowType is an attribute which is used to the parent class because if you define the complex class as the property of class then it would be very difficult for the compiler during the de-serialization process.


49) Give an example of KnowType.

See this example:




You may also like:


Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA