WCF Interview Questions and Answers (209) - Page 7

What are the benefits of WCF?

The benefits include the following

1. Transactional support
2. Asynchronous one-way messaging
3. Interoperability
4. Independent versioning
5. Platform Consolidation
What are the principles WCF implement?

WCF services effectively communicates with the clients through these principles.

1. Explicit boundaries
WCF services function using the defined interfaces to identify the communications between server and client that flow outside the boundaries of the service

2. Independent services
WCF services are deployed and managed independently and each service interaction is independent of other interactions. They are independent of deployment, installation and version issues.

3. Schema and contract based communication
WCF services communicate with clients by providing only the schema of the message and not its implementation classes. The service implementation can be changed if required without impacting the clients

4. Policy based compatibility
Compatibility between WCF services and clients at runtime is determined using published policies. Policies help separate the description of the service fro its implementation details.
What are the four layers in WCF architecture?

SOA based WCF architecture has four layers.

1. Contracts
It describe the WCF message system. This is achieved by three contracts with policies and bindings.
1. Service Contract - Describes the method signature of the service using C# or VB
2. Data Contract - Enables .NET types to be in XML
3. Message Contract - Defines the structure os the SOAP message exchanged between the service and client
4. Policies and Bindings - Defines the security level required by the clients

2. Service Runtime
This includes the behaviors that occur when service is running.

3. Messaging
This layer contains the channels that process messages and operate on messages and message headers

4. Hosting
Describes the ways in which WCF service can be hosted.
List the behaviors included in Service Runtime of the WCF layer?

The following behaviors are included in the WCF Service Runtime layer..

1. Throttling behavior
Throttling behavior provides the options to limit how many instances or sessions are created at the application level.

2. Error behavior
By implementing IErrorHandler interface WCF allows an implementer to control the fault message returned to the caller and also it performs custom error processing such as logging

3. Metadata behavior
Through the metadata behavior we can publish metadata of the service by configuring an endpoint to expose the IMetadataExchange contract as an implementation of a WS-MetadataExchange (MEX) protocol. By default it is disabled.

4. Instance behavior
This behavior specifies how many instance of the service has to be created while running WCF.

5. Transaction behavior
This is used to enables the rollback of transacted operations if a failure occurs.

6. Dispatch behavior
This behavior controls how a message is processed by the WCF Infrastructure.

7. Concurrency behavior
Concurrency behavior measures how many tasks can be performed simultaneously

9. Parameter Filtering
This demonstrates how to validate the parameters passed to a method before it is invoked.
What is a duplex WCF service?

A duplex service contract refers to exchange of messages in which both server or client endpoints can send messages to the other independently.

A duplex service can send message back to the client endpoint providing event like behavior.
How can you specify a duplex service?

A pair of interfaces is required to create a duplex contract.

1. Service Contract interface - Describes the operations that a client can invoke.
2. Callback Contract interface - Describes the operations that service can call on client.

The service contract should specify a callback contract in the System.ServiceModel.ServiceContractAttribute.CallbackContract property.
Give an example of a duplex service


public interface ICalculatorDuplex
[OperationContract(IsOneWay = true)]
void FunctionClientCanCall();

public interface IRespondBackCallback
[OperationContract(IsOneWay = true)]
void FunctionServiceCanCall(double result);

Explain the functionality of the Message layer in WCF.

The Messaging layer contains channels that process messages and operate on messages and message headers. The messaging layer has eight channels which defines the possible formats and data exchange patterns.
The eight channels are divided into two categories.

1. Transport Channels
These channels helps reads and write messages from the network.
1. WS Security Channel
2. WS Reliable MessagingChannel
3. Encoders:Binary/ MTOM/ Text/ XML

2. Protocol Channels
These channels implement message processing protocols.
1. HTTP Channel
2. TCP Channel
3. TransitionFlow Channel
4. NamedPipe Channel
5. MSMQ Channel
What is a Throttling behavior in WCF?

Throttling behavior of the WCF service holds the configuration for three limitations that control the amount of resources that your service hosting can allocate to deal with the client request. Thus it enables to
1. Manages resource Usage
2. Balances performance load

How can we specify the throttling behavior for a WCF service?

Throttling behavior is specified by the following three parameters.

1. MaxConcurrentCalls - Total no of concurrent calls service will accept
2. MaxConcurrentSessions - Total no of sessionful channels service will accept
3. MaxConcurrentInstances - Total no of service instances will be created for servicing requests.

It can be specifed either through code or configuration file. It requires the "System.SystemModel.Behavior" namespace to be included.
What is a metadata export?

Metadata Export is the process of describing the service endpoints and projecting them into a parallel, standardized representation that clients can use to understand how to use the service.
How to publish service metadata?

WCF services publish its metadata by exposing one or more metadata endpoints. Publishing service metadata makes service metadata available using standardized protocols, such as MEX and HTTP/GET requests.
Metadata endpoints are the same as other service endpoints and have an address, a binding, and a contract.
You can add metadata endpoints to a service host in configuration or in code.
In WCF, suppose you have a derived class inherited from a datacontract class, will the derived class automatically have a datacontract as well ?

The Data contract is not inherited, so any derived class, would have to be explicitly declared as having a Data contract attribute as well.

Thanks and Regards
In WCF, if your service wants an authentication before it is used then what is the best way to handle an authentication mechanism with WCF?

The best way to handle this would be to design a Message contract that
accepts these authentication tokens in the header of the message.

Thanks and Regards
What is meant by WS Addressing Standard in WCF ?

The address for an endpoint is a unique URL that identifies the
location of the service. The address should follow the Web Service Addressing (WS-Addressing) standard, and they are :-

(1) Scheme - This is typically “http” followed by a colon.

(2) Machine - Identifies the machine name, which can be a public URL such as “www.google.com" or a local identifier such as “localhost”.

(3) Port - The optional port number, preceded by a colon.

(4) Path - The path used to locate the service files. Typically, this is just the service name, but the path can consist of more than one level when a service resides in a directory structure.

Thanks and Regards
Give some examples of varying address in WCF ?

An address can vary, depending on whether it is hosted by Microsoft Internet Information Services (IIS) on a public network or hosted locally on an internal network computer. It can also vary, depending on the protocol the binding uses. For example, all the following could be valid addresses:

(1) http://www.google.com/MyService/
(2) http://localhost:9800/Service1/MyService/
(3) net.tcp://localhost:9801/MyService/

Thanks and Regards
What namespace is used by ASMX and WCF respectively for serialization ?

For serialization, WCF uses the System.Runtime.Serialization namespace for serialization.

Web service(i.e), ASMX uses System.Xml.serialization namespace.

Thanks and Regards
ServiceContract, DataContract and MessageContract maps to which web services standard ?

(1) ServiceContracts maps to WSDL
(2) DataContracts maps to XSD
(3) MessageContracts maps to SOAP

Thanks and Regards
What is a WCF Test Client ?

WCF Test Client is a GUI tool which enables us to enter parameters, invoke services with these parameters and view the responses returned by services.

After you create a new WCF service project and press F5 to start the debugger, the WCF Service Host begins to host the service in your project. Then, WCF Test Client opens and displays a list of service endpoints defined in the configuration file. You can test the parameters and invoke the service, and repeat this process to continuously test and validate your service.

Thanks and Regards
In WCF, is returning a void return type returns anything ?


public interface IService1
void Employee(string value);

In the above case, the response message is still being sent back to the client. The difference is it sends an empty SOAP body.
So, returning void doesn't mean it will not return anything to the Client !

Thanks and Regards
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories