Share this:

145 WCF Interview Questions and Answers

1. What is WCF?
Answer: Windows Communication Foundation (WCF) was called Indigo. It is a run-time platform and a set of APIs in the .NET Framework to build, configure, and deploy Service Oriented Applications and was deprecated for developing advanced HTTP-based web services. It can support multiple languages and multiple platforms.

2. What is mean by ABC of WCF?
Answer: ABC is stand for Address, Binding and Contract. It can define the endpoint of a service.

Address means where we get the service.

Binding means how we can access the service.
Contract means what we will get from Service.

3. What is difference between WCF and Web Services?
Answer:

Features Web Services WCF
Hosting They are hosted in IIS. They are hosted in IIS, windows service, self-hosting and more.
Programming It is required to add a <Web Service> attribute to the class. It is required to add a <Service Contract> attribute to the class.
Operations The duplex operation has not been supported in the case of web services. The duplex option is supported freely in the case of WCF.
Protocol Data will be exchanged using the HTTP protocol only. Data will be exchanged with HTTP. TCP, MSMQ and more.
Encoding Custom and XML   Encoding MTOM, XML, Binary, Custom
Services Security Secure, reliable messaging, transaction

 

4. What is mean by Service, Message and client?
Answer: Service – A Self-contained business functionality that is independent of other services.

Message –Message is a service which communicates with each other with the help of messages.

Client – Client is party that consumes the service.

5.  Mention what are the main components of WCF?
Answer: Main components of WCF are

Service is the working logic.

Host is path where the data is saved. Example for exe, process, windows service

Endpoints are the way the service is exposed to the outside world.

6. Explain how does WCF works?
Answer: In WCF all units of functionality are defined as services as it follows the “Software as a Service” model.  Each point is a portal or connection either with the client or other services in communication. WCF is a program which exposes a collection of endpoints.

7. Explain the difference between ASMX web services and WCF?
Answer: ASMX has a design to send and receive messages using SOAP over HTTP only. But WCF can exchange messages in any format over any transport protocol (HTTP, TCP/IP, MSMQ, NamedPipes, etc).
ASMX web services are hosted only in IIS but WCF service has the following hosting options:

1.IIS

2.WAS (Windows Process Activation Services)

3.Console Application

4.Windows NT Services

5.WCF provided Host

6.ASMX Security is less.  Authentication and authorization can be done using IIS and ASP.NET security configuration and transport layer security. WSE can be used for message layer security
7.WCF can offer a security programming model for all protocol. It will support many of the similar capabilities of IIS and WS-* security protocols. It will provide support for claims-based authorization which provides finer-grained control over resources than role-based security. WCF security is more consistent regardless of the host which is used for implementing WCF service.
8.ASMX web services will use XmlSerializer for serialization but WCF will use DataContractSerializer which is better in performance than XmlSerializer.

8. Explain how many types of contract does WCF define?
Answer: WCF can define following types of Contracts:

1.Service Contracts

2.Data Contracts

3.Fault Contracts

4.Message Contracts

9. List the ways of hosting a WCF service?
Answer: The following are the ways of hosting a WCF service :

1.IIS

2.Self-Hosting

3.WAS (Windows Activation Service)

10. What is address syntax and the different formats of WCF transport scheme?
Answer: The following is address syntax of WCF transport scheme

[transport]:// [machine or domain] [: optional port] format

11. What are duplex contracts in WCF?
Answer: In WCF, Duplex messaging or call-back is used for communicate with the client. Duplex messaging in WCF is done as TCP, Named pipe and even HTTP over different transport system. Altogether this is called as duplex contracts in WCF.

12. What are the different instance modes in WCF?
Answer: Following instance modes are available in WCF:

1.Per Call: Per Call instance is created for each call. It is efficient in terms of memory but sessions are need to be maintained.

2.Per Session: Per Session instance is created for a complete session of a user.
3. Single: Single instance is created and it is shared among all. It is less efficient in terms of memory.

13. What is a Service Proxy in windows Communication Foundation?
Answer: In WCF, a service proxy will enable applications for interacting with WCF service by sending and receiving messages.  WCF is a class which will cover service details like service path, service implementation technology, platform and communication protocol etc.  Therefore when the application interact the service through proxy, it will give the impression of communication with a local object.

14. What is SOA?
Answer: SOA is stands for Service Oriented Architectural which is a collection of services and determines the way to communicate two computing entities with each other to achieve certain business functionality.  It also determines how one entity will work on behalf of another entity.

 

15. List out the types of Data Contracts in WCF?
Answer: There are following types of Data Contracts

1.Data Contract is used to define the class.

2.Data Member is used to define the properties.

16. List out three types of transaction manager WCF supports?
Answer: The following are the types of the transaction manager which are supported by the WCF :

1.Light Weight

2.WS- Atomic Transaction

3.OLE Transaction

17. What are the MEPs available in WCF?
Answer: Following MEP (Message Exchange Pattern) are available in WCF :–

1.Data Gram

2.Request and Response

3.Duplex

18. What is the namespace that is used to access WCF service?
Answer: System.ServiceModel is used for accessing WCF service.

19. What are the types of binding available in WCF?
Answer: Following are the types of binding available in WCF :

1.BasicHttpBinding

2.NetTcpBinding

3.WSHttpBinding

4.NetMsmqBinding

20. What is DataContractSerializer?
Answer: Serialization is the process of changing an object instance to a portable and transferable format. And serialization of data is called as DataContractSerializer.

21. What are the various address format in WCF?
Answer: The following are various address format in WCF :

1.HTTP Address Format: à http:// local host:

2.TCP Address Format:à net.tcp://localhost:

3.MSMQ Address Format:ànet. Msmq://localhost

22. What is REST and what is the problem of it and how it can be resolved?
Answer: REST means Representational State Transfer to design network application. It is dependent on a stateless, client server, cacheable communications protocol.  WCF supports SOA and not REST because it requires a lot of configuration in order to create HTTP REST service using WCF.  This can be resolved by asp.net  API.

23. What is the different isolation levels provided in WCF?
Answer: The following isolation levels are provided in WCF

1.Read Uncommitted

2.Read Committed

3.Repeatable Read

4.Serializable

24. What is the biggest advantage of WCF?
Answer: Load Balancing is the biggest advantages of WCF.

25. What is the biggest disadvantage of WCF?
Answer: The biggest disadvantage of WCF is Microsoft holds control over its APIs.

26. Name two types of approaches which can be taken when programming WCF.
Answer:Imperative and Configuration based are two programming approaches which can be taken when programming WCF.

27. What are the required tools for WCF?
Answer: Following are the required tools for WCF

1.Svcutil.exe

2.FindPrivateKey.exe

3.ServiceModelReg.exe

4.ComSvcConfig.exe

5.SvcConfigEditor.exe

6.SvcTraceViewer.exe

7.WsatConfig.exe

8.MMC Snap-in

9.WFServicesReg.exe

10.WcfSvcHost.exe

11.WcfTestClent.exe

28. What are the transport layer protocols used in WCF?  
Answer: Following are transport layer protocols used in WCF                               

1.HTTP

2.HTTPs

3.TCP

4.Named pipes

29. What is one main difference between HTTP and TCP protocol in WCF?           
Answer: HTTP is connectionless protocol and TCP is based on connection protocol.


30. What is the task of TCP protocol in WCF?                          
Answer: Following is the task of TCP protocol in WCF                                    

1.TCP can notify the sender about packet delivery.

2.TCP can guarantee that order in which the packets are 3.delivered is the same as they are sent.

4.It can ensure the non -duplication of packets.

5.It can  retransmit lost or undelivered packets.

31. Where can we use named pipes protocol in WCF Application?                              
Answer: Named pipes protocol can be used when communication is required between WCF applications on the same machine and do not required to communicate with another machine.

32. What are different servers used to deploy the WCF services?                                  
Answer: There are following various servers used for hosting WCF services:

1.WIndows NT Services

2.Windows Forms

3.Console applications

4.IIS

5.Activation Services(WAS)

33. What is the best hosting of wcf services?    
Answer: IIS server is the best for hosting services because of  to its scalability reliability and security.

34. Does WCF supports Ajax and JSON data format?  
Answer: WCF can support ASP.NET ajax and JSON data format.

35. What is the use of Ajax and JSON in WCF application?
Answer: ASP.NET Ajax and JSON can allow WCF services to expose operations to AJAX Client .JSON is an effective data format which is used for quickly exchange Small amount of data between the Ajax can enable web services and their clients.

36. Which Microsoft Ajax Library does contain proxy classes ?                                    
Answer: Sys.Net.WebServiceProxy Class can be used for ajax Integration and JSON support in WCF.

37. What is the Enhanced features of WCF in visual studio 2010 ?                           
Answer: There are following new enhanced features introduces in visual studio 2010 :
1.It can support more configuration based activity.

2.It can support System.Web.Routing Integration .

3.It can support multiple IIS site bindings .

4.It can provide Routing Support.

5.It can provide WS discovery support.

38. What is the various types of communication pattern used by the wcf client  to communicate with the services ?
Answer: 1. One-way:It can communicate in a single direction which flows from a client to services without any reply from the service.The client has no ides about the success or failure of the message.

2.Request-Reply: When a client will send a message to a service, It will await for the response from the services. The client will not make further execution until it receives the reply from the services.

3.Duplex: It is bidirectional communication between server and client without any waiting.

4.Asynchronous : In this client will send a request to a server and can starts another process without waiting for the response of that request.

39. What is WCF data Service Explain?                                                                              
Answer: WCF data services is a Microsoft technology used for creating and consuming data services,that can make it easy to separate the presentation layer from the data layers while working with them. Microsoft integrated the concept of WCF Data service with visual studio 2010 and .NET Framework 4.0 to work with Data services easily.

40. What are the Advantages of WCF Data service?                                                       
Answer: The following are advantage of WCF Data services:
1. It can support Entity -relationship conventions to use Entity data model (EDM).
2.It will include different client libraries as .NET Framework client applications and silverlight applications.

3.It can help to update the resources.

41. Can we have multiple endpoints for different binding?
Answer: Yes, for different binding types, we can have multiple endpoints. An endpoint with wsHttpBinding and netTcpBinging.

42. What is the full form of URL ,URI and URN?                
Answer: URL stands for Uniform Resource Locator

URI stands for Uniform Resource Identifier

URN stands for Uniform Resource Name

43. What is Web service?
Answer: Web service is hosted on website or a service which can be consumed through web is called as webservice.

It is created by following webservices specification(ws-*)

44. What is wsdl?
Answer: WSDL  is schema definition language that can describe complete webservice. One can create proxy by using WSDL document content.

45. Explain service contract, data contract, message contract, fault contract.  
Answer: ServiceContract:

It can provide information regarding operations provided by service which is too exchanged between client and service.

 DataContract:

It can provide information regarding Data which is to be exchanged between client and wcfservice. serialization and deserialization are carried out by using predefined serializer called datacontract serializer.

MessageContarct:

It can provide information regarding Data which is to be exchanged between client and wcfservice but information will be directly embedded within soap messages.

  FaultContract:

It can provide information regarding runtime error (Exception) which is to be exchanged between client and wcfservice.

46. What are the different types of exceptions in WCFService?
Answer: There are three types of exceptions.

CommunicationException:
It  is raised when there is problem with network or service.

ObjectDisposedException:

It is raised when request has been made after closing proxy or binding mismatch.

FaultExceeption:

It is runtime error produced while processing request due to input provided.

 

47. How DataContractSerializer is different from XmlSerializer?
Answer: DataContractSerializer is approximately 10% faster than XmlSerializer. DataContractSerializer has almost no control over how the object is serialized.

48. Which standard binding could be used for a service that was designed to replace an existing ASMX web service?
Answer: The basicHttpBinding standard binding is designed for exposing a service to replace an existing ASMX web service.

49. Explain different modes of security in WCF?
Answer: Following are the different mode of security
 Transport Level security: It will provide security at the transport layer itself.

At Transport level, it is required to concern about integrity, privacy and authentication of message as it travels along the physical wire.
<netTcpBinding>

<binding name=”netTcpTransportBinding”>

<security mode=”Transport”>

<Transport clientCredentialType=”Windows” />

</security>

</binding>

</netTcpBinding>

 

 Message Level Security:  In message level security, message is required to secure. We have to encrypt the message before transporting it.

<wsHttpBinding>

<binding name=”wsHttpMessageBinding”>

<security mode=”Message”>

<Message clientCredentialType=”UserName” />

</security>

</binding>

</wsHttpBinding>

Based on the requirement security mode can be mixed as follows
<basicHttpBinding>
<binding name=”basicHttp”>

<security mode=”TransportWithMessageCredential”>

<Transport />

<Message clientCredentialType=”UserName” />

</security>

</binding>

</basicHttpBinding>

 

50. What are features of REST?
Answer: REST has following features

1.HTTP get support for GET,POST,DELETE and POST.

2.In HTTP world every resource are identified by a URI.

51. What is mean by HTTP REST services and WCF REST Services?
Answer: HTTP REST services has the features like
1.HTTP get support for GET,POST,DELETE and POST.

2.In HTTP world every resource are identified by a URI.

WCF REST services are Microsoft’s implementation of HTTP REST.

 

52. What is Problem with WCF REST and how it is solved?

Answer: WCF require lots of configuration to create WCF REST which is a tedious task.

Asp.NET Web API can resolve this problem.

 

53. What are dead letter queues?
Answer: Client and the server do not run at one time in a queue.  Sometimes it may happen that a message is lie in queue for long time to pick up by the server or client.  But there are some cases where a message has no use after a certain time.

 

54. What are the advantages of WCF?
Answer:Following are the advantages of WCF
1.WCF is interoperable when compared to .Net

2.WCF service can provide better reliability and security in compared to ASMX web services.

3.There is no need to make much change in code to implement the security model and changing the binding in WCF.
4.WCF will have integrated logging mechanism, changing the configuration file settings  which provides this functionality.

 

55. What are the features of WCF?
Answer: Transactions:

A transaction is a unit of work and it can ensure that everything within that transaction either succeeds as a whole or fails as whole.

Hosting:

WCF hosting can allow services to be hosted in a handful of different environments, such as Windows NT Services, Windows Forms, and console applications, and IIS (Internet Information Services) and Windows Activation Services (WAS).

Security:

WCF will enable for integrating application into an existing security infrastructure, along with Extend beyond the standard Windows-only environments by using secure SOAP messages.

Queuing:

WCF can enable queuing by providing support for the MSMQ transport.

 

 

56. What are the types of performance counters?

Answer: There are following types of performance counters:

1.Service

2.Endpoint

3.Operation

 

57. Can we have two-way communications in MSMQ?
Answer: Yes, we can have two-way communications in MSMQ.

 

58. What are Volatile queues?
Answer: Volatile queues are used to deliver message in proper time and ensure that they are not lost.


59
. What is a poison message?
Answer: Poison messages are messages which cannot be processed and if they are on the top of a queue other messages will never get a chance.

This can happen in any architecture which has first-in first-out queues, including MSMQ.

 

60.What is KnownTypesAttribute in WCF?
Answer: The KnownTypeAttribute attribute will allow information about derived types to be included in the data contract.

 

[DataContract(Namespace=”http://Microsoft.ServiceModel.Samples”)]

[KnownType(typeof(ComplexNumberWithMagnitude))]

public class ComplexNumber

{

[DataMember]

public double Real = 0.0D;

[DataMember]

public double Imaginary = 0.0D;

 

public ComplexNumber(double real, double imaginary)

{

this.Real = real;

this.Imaginary = imaginary;

}

}

[DataContract(Namespace=”http://Microsoft.ServiceModel.Samples”)]

public class ComplexNumberWithMagnitude : ComplexNumber

{

public ComplexNumberWithMagnitude(double real, double imaginary) :        base(real, imaginary) { }

[DataMember]
Answer: public double Magnitude

{

get { return Math.Sqrt(Imaginary*Imaginary  + Real*Real); }

set { throw new NotImplementedException(); }

}

}

61. What is proxy?
Answer: Proxy is an application program that works on behalf of another application.

We need proxy when consuming operations and data of service.

 

62. What is SOAP(Simple Object access protocol)?
Answer: SOAP is a combination of HTTP and XML.  Client and service communication are carried out with the help of SOAP messages.

 

63. What is .disco file?
Answer:.disco file is called as discovery file that can provide link to wsdl document and link to service.

64. What is UDDI(Universal description discovery integration) ?
Answer: UDDI is open specification that can specify how a service are discovered and integrated with application.

 

65. What is UBR(UDDI business registry)?
Answer: UBR can be described as complete implementation of UDDI. UBR are implemented as local UBR where services with local server for company use can be located. Public UBR, project has been stopped from 1st Jan 2006. Webservices can be located through internet by using webservices search engine.

66. What are the important parts of WCFService?
Answer: There are following important parts of WCFService

a)Serviceclass: It will provide complete implementation of operations and data of service. There are only one service in a service. All service contracts of service can be implemented in service class.

b)Endpoint: Client communicates with service with the help of endpoint only

c)Hosting Environment: An application that will provide environment to run the service. Many services can be hosted on a single hosting application.

 

67. What are the important parts of Endpoint?
Answer: There are following important parts in Endpoint
a) Address: Depending upon transmission protocol appropriate format must be used to locate service effectively.

Http:http://localhost:8080/MyService

Tcp:net.tcp://localhost:8010/MyService

Namedpipe:net.pipe://localhost/MyService

 Msmq:net.msmq://<QueueName>/<address string>

 b)Binding:It can specify how to communicate with service.   1.Transmission protocol

2.Message format

3.Security protocol.

There are predefined bindings provided by Microsoft according to transmission protocol.

Http:
 basicHttpBinding

wsHttpBinding

wsDualHttpBinding

wsFedrationBinding

 Tcp:
 netTcpBinding

peerTcpBinding

NamedPipe:

netNamedPipeBinding

   Msmq:

netMsmqBinding

MsmqIntegrationBinding

 

c)Contract: it can specify what can be consumed from service.              

68. What is MexPoint?
Answer: MexPoint is endpoint which is used to communicate with service for consuming Metadata of service. Client application will request for description of service through mexpoint. Based on meta data received, proxy are generated.

   

69. What is the difference between endpoint and Mexpoint?
Answer: Endpoint is used for requesting and consuming operations and data of service.

Mexpoint is used for requesting and consuming metadata of service which is needed for proxy creation.

 

70. What are different bindings for mexpoint creation?
Answer: Binding for me point creation is mexHttpBing, mexTcpbinding, mexNamedPipeBinding.

 

71. What is the predefined contract for mexpoint?
Answer: Predefined contract for mexpoint is IMetadataExchange.

72. What are different types of Hostings?
Answer: There are following types of hosting:

 IIS Hosting service is hosted one of website that is run on IIS  6.0 or more and supports only Http. Service are consumed  like a webservice.

Self Hosting: Services are hosted on one of .net enabled application like console app, Win forms app, Wpf app or Windows Service. It can supports all protocol.

WAS hosting: services are consumed as webservice or remote service within .net applications, consumed like a webservice in non .net applications, and support all protocols.

73. What is the service?
Answer: A set of functionality which is exposed to the world is called service.

74. What is service proxy in WCF?
Answer: WCF Proxies are used for communicating between client and server. The communication will take place by exchanging the messages in the form of requests and responses. It has the details such as Service Path, Protocol details and so on.

75. What is “Service Contracts” in WCF?
Answer: The Service Contracts attribute will be used at the service level for WCF service. It can provide the list of operations which can be performed from that service.

Service Contracts can be defined as:

[SeviceContract]

76. What do you mean by client?
Answer: The client of a service is the program unit which can consume its functionality. A client is Console application, Windows form, WPF or Silverlight class or ASP.Net page etc.

77. Which are the different isolation levels in WCF?
Answer: In WCF has following list of different isolation levels :

Read Uncommitted: It is called dirty isolation level which can make sure that corrupt Data will not be read. Read Uncommitted is the lowest isolation level.

Read Committed: It can ensure not to read the data which has been changed by any other application and not committed. Read Committed is the default level.

Repeatable Read: It can stop the usage of dirt read and non-repeatable read. It will state which data fetched through a query are locked and can not be updated by any other transaction.

Serializable: It will not allow any changes and addition of new data untill the transaction has been completed. It is  to very restrictive level.
Snapshot: It can raise an error on modifying a data which are already changed by any transaction.

78. Explain the WCF RIA?
Answer: WCF RIA is the framework to develop the n-tier application for RIA (Rich Internet App). It can be used in Rich Internet Apps like Silverlight, AJAX etc. WCF RIA are used for solving the major problems like Tight Coupling.

79. How would you generate a proxy for WCF?
Answer: Proxy can be generated  for WCF by following steps:Using Visual Studio Using SvcUtil

80. How many types of binding are there in WCF?
Answer: WCF can support nine types of bindings:

·       Basic binding

·       TCP binding

·       Peer network binding

·       IPC binding

·       Web Services binding

·       Federated Web Service binding

·       Duplex WS binding

·       MSMQ binding

·       MSMQ integration binding

81. What are the transport schemas supported by WCF?
Answer: WCF will support the following transport schemas:

·       HTTP

·       TCP

·       PEER network

·       IPC (Inter Process Communication)

·       MSMQ

82. How can we enable the metadata information of the service?
Answer: We can enable the metadata information of the service by following method:
 For Default Endpoint: <serviceMetadata> tag can be used in web.config file. endpoint are not specified.
 For Custom Endpoint: <serviceMetadata> tag can be used in web.config file. Defined endpoint are specified.

83. Which bindings are used for metadata configuration in WCF?
Answer: Following bindings are used for metadata configuration on WCF:
1.mexHttpBinding

2.mexNamedPipeBinding

3.mexHttpsBinding

4.mexTcpBinding

84. How can you test a WCF application without creating a client application?
Answer: We can test a WCF application using a tool called wcftestclient.exe without creating a client application. It is opened from visual studio command prompt.

85. What is the transport and message reliability?
Answer: Transport reliability can offer point-to-point guaranteed delivery at      the network packet level, and guarantees the order of the packets. Message reliability can deal with reliability with message level independent of number of packets required to deliver the message.

86. What is the usage of receiveTimeout property in WCF?
Answer: The recieveTimeout property can be used to get/set the time interval for making a connection active.

87. What is the one-way mode in WCF?
Answer:  In one-way mode, client can send a request to the server and will not wait till the response comes in WCF. One way mode will not care for the request is failed or succeeded.

88. What are the different types of transaction managers supported by WCF?
Answer: There are following types of transaction managers supported by WCF:

Light Weight

WS-Atomic Transaction

OLE Transaction

89. How many MEP are allowed in WCF?
Answer: In WCF, three types of MEP  (Message Exchange Pattern) are allowed:

1.DataGram

2.Request and Response

3.Duplex

90. What is Throttling in WCF?
Answer: Throttling can be used for limiting the sessions or instances to be created at an application level and it can boost the performance in WCF.

91. What is the usage of maxConcurrentCalls in Throttling?
Answer: The maxConcurrentCalls attribute in throttling is used for limiting the total number of calls that are going to the service instances. The default value of maxConcurrentCall is 16.

92. What is the request-reply mode in WCF?
Answer: In the request-reply mode, When a client will make a request to a service, it has to wait until it receives the response back. If the response will not be received in the given time, it will indicate an error. If the client received the response then next instructions can be executed.

93. What is Callback mode in WCF?
Answer: In callback mode, WCF on the call back will call the method of client and WCF service will act as a client and client will act as a service.This mode can not be supported by “HTTPBinding” therefore WSDualHttpBinding” is used in the mode.

94.How Can We Use MessageContract Partially with DataContract for a Service Operation in WCF?
Answer: No, MessageContract can not be used partially with DataContract for a service Operation in WCF.

95. Which Standard Binding could be used for a Service that was designed to replace an Existing ASMX Web Service?
Answer: The basicHttpBinding standard binding is designed for exposing a service to replace ASMX/ASP.NET web service. This enables to support existing clients as applications upgrades to WCF.

96. How Can We Achieve Operation Overloading While Exposing WCF Services?
Answer: By default, WSDL can not support operation overloading. Overloading behaviour are achieved by using Name property of OperationContract attribute.
[ServiceContract]

interface IMyCalculator

{

[OperationContract(Name = “SumInt”)]

int Sum(int arg1,int arg2);

 

[OperationContract(Name = “SumDouble”)]

double Sum(double arg1,double arg2);

}

When the proxy is generated for these two operations, it has 2 methods with different names, i.e., SumInt and SumDouble.

97. Which styles of models are supported in WCF?
Answer: WCF service Can  supports two styles of models:

RPC style: We uses the serialize types and it can  provide the feature which is available for local calls.

Message style: WCF will allow the message header to be customized and it can allow us to define the security for body and header messages.

98. Describe following types of binding in WCF.
Answer:
Basic Binding
Web Service Binding

IPC Binding

TCP Binding

Peer Network Binding
MSMQ (Microsoft Message Queuing) Binding

MSMQ integration binding

 

Basic Binding

It can use HTTP as the transport and text/XML as the default message encoding. Basic Binding is offered by the BasicHttpBinding class and it is suitable to communicate with ASP.NET Web services (ASMX).

Web Service Binding

This is offered by WSHttpBinding class. It can use protocols for transport  but can also provide WS-* specifications such as WS-Reliable Messaging, WS-Transactions, WS-Security, etc.

IPC Binding

It will use Named pipe protocol and offered by the netNamedPipeBinding class. IPC is the fastest and secured Binding. It will support SOAP security, transaction, and reliability.

TCP Binding

It will use TCP protocol for communicating within the same network and can encode the message in binary format. This is offered by NetTcpBinding class. It will provide a secure and reliable binding environment for .Net to .Net cross-machine communication.

Peer Network Binding

It can make use of peer networking as transport along with TCP protocol. This is provided by NetPeerTCPBinding class. It can be used in file sharing systems like a torrent. It will fully support SOAP security, transaction, and reliability.

MSMQ (Microsoft Message Queuing) Binding

It will use MSMQ for transportation and will support detached message queuing. It is offered by NetMsmqBinding class and is used for providing secure and reliable queued communication for the cross-machine environment.

MSMQ integration binding

This is offered by MsmqIntegrationBinding class. It will enable communication with existing systems which which will communicate through MSMQ.


99. How
transaction works in WCF?
Answer: Transaction means more than one party are involved in order to complete one single logical operation.
WCF transaction will follow two faces.
Phase 1: Transaction manager will check whether all services are completed and ready to commit. This phase is also called as prepare phase.
Phase 2: Real commit will happen in this phase. It is called as as Commit Phase.

100. What is .svc file?
Answer:.svc file is a file in which service is defined and it is the point of contact from the consumers. It will contain name of service and code behind file name.


101.Where the transaction manager does resides, in service side or client side?
Answer: At client side

102.What is the functionality of the Message layer in WCF?
Answer: Message layer is consisting of channels and it will specify formats and data exchange patterns which can be used to communicate with the services. These channels can process messages and will operate on message and message headers. The Message layer has eight channels which are categorised into two as described below:

Transport Channels can help to read and write messages from the network.

1.WS Security Channel can enable to secure the message by implementing the ws-security specification in the messaging layer of a service.

2.WS Reliable Messaging Channel protocols can provide guarantee to deliver the message over channels.
3.Encoders can provide the number of encodes for message such as Text, Binary, XML, and MTOM.

 

Protocol Channels will be used for implementing message processing protocols.
1. HTTP Channel can specify that HTTP is used for delivering a message.

2.TCP Channel can specify that TCP is used for delivering the message.

Transaction flow Channel:- It define the pattern in which a message is transacted.
Named Pipe Channel:-It enables inter-process communication (IPC).

MSMQ Channel:- It enables services to inter-operate the MSMQ Applications.

103. What is WCF unexpected response(413) means?
Answer: The remote server  will return an unexpected response: (413) means Request Entity Too Large.

104. Whats the difference between Allowed and Mandatory in TransactionFlow attribute?
Answer: TransactionFlowOption are allowed means client calls the service in transaction.
TransactionFlowOption are mandatory means client will call the service in transaction.

105. What are the behavior managed by Service RunTime Layer in WCF ? 
Answer: Throttling behavior:- The number of processed messages are varied according to demand of services.

Error Behavior:- It will specify the action can be taken. Message provide error during service runtime.

Instance behavior:-  It will specify the number of service instance which are available to process a message.

Meta Data Behavior:- It will specify meta data which is available or not across the network.

Message Inspection:- It can inspect all the message during service runtime.

Transaction behavior:- It can roll backs the transactions, if any process are failed during service runtime.

Dispatch Behavior:- It can determine that how a message is handled and processed by the WCF infrastructure.

Concurrency behavior:- It can specify whether the message will be processed sequentially or concurrently by the service.

Parameter filtering:- It can  filter the message header and executes preset actions.

106. What is the need for WCF?
Answer: WCF is needed because the service which are created by  WCF are supported by different protocols.

107. What are the advantages of WCF.
Answer: Following are the advantages of WCF

1.Service Oriented,
2.location Independent
3.Language Independent
4.Platform Independent
5.Support Multiple Operations
6.Support all protocol

108.What are Service Oriented Design Principles?
Answer: There are following Service-oriented principle in SOA   Explicit Boundaries: According to this principle, a service will be deployed anywhere.It can be easily and freely accessed by other services, independent of the environment or development language of the other services.

Services are autonomous: According to this SOA principle, each service must be managed. It must be versioned differently because they should not affect other services in the process. Contracts, after publishing, will not be changed. Services are required to be isolated and decoupled for accomplishing the goal of making them autonomous.

Services share schema and contract, not class: According to this  SOA principle, services will not pass classes and types; they can pass schemas (data) and contracts (behaviors). This will allow for a loosely coupled system where the service will not care about type of environment the other service is executing on. The information which are passed is 100% platform independent.
Service compatibility is determined based on policy: According to this SOA principle, each service will have its own compatibility level and it will know how it interacts with other services. Services can start communicating, if they have similar policies. If two services will not satisfy each other’s policy requirements, they will not be compatible with each other.

109. What is WS -* Protocols?
Answer: Extended SOAP, WS-* protocols  are developed with semantics which will be reused in various application scenarios.

WS -* protocols has a set of protocols means standards and specifications which will help us to implement certain needs and behaviors of a service. These protocols can explain how to exchange messages in a secure, transactional, and reliable way by using the headers in the SOAP message. WCF will implement the WS -* protocols by WsHttpBinding class. This binding will make use of some of the WS -* protocols and can add the needed behaviors, like transactional message calls, reliability, discovery, and addressing.

110. What is Concurrency Management in WCF?
Answer: Concurrency management has been related to the Instance management in WCF. Instance management will specify how the service instances will be created while Concurrency management can specify how many concurrent requests are handled by the service instances. Service instance can be made thread-safe by concurrency management.  In per-session service instance, concurrency management is required because it is not thread-safe since multiple requests of a client will be served by a single service instance. A single service instance  also requires concurrency management, since it is also not thread-safe because multiple requests of all clients are served by a single service instance.

111. What was the code name for WCF?
Answer: Indigo was the code name of WCF.

112. What is Impersonation?
Answer: Impersonation is a way for authorizing a client identity to access the service domain’s resources. The service resources can be local files or database tables and it resources will be accessed by using the WCF service’s process identity and impersonation is disabled.

113. What is service versioning?
Answer: Service versioning helps in backward compatibility with existing clients.
Service is required to change after initial deployment of the WCF service, for a variety of reasons such as to changee business needs or to fix other issues. Each change in existing service will introduce a new version of the service.

114. What is WCF Data Service?
Answer: WCF Data Services will use OData (Open Data Protocol) protocol to generate query or to manipulate the data. WCF Data Services can be built on top of WCF REST Services which is a RESTful service for supporting CRUD operations on the database using the HTTP protocol. It will support all database operations using URI. DATA protocol can expose data from the relational database, File systems, Web sites, services etc. It can support XML or JSON format for exposing the data.

115. Shows a sample Services Client configuration file?
Answer:  A sample client config file is like below

 

<system.serviceModel>

 

<client>

 

<endpoint name = “MyEndpoint”

 

address  = “http://localhost:8000/MyService/”

 

binding  = “wsHttpBinding”

 

contract = “IMyContract”

 

/>

 

</client>

 

</system.serviceModel>

116. How to set the timeout property for the WCF Service client call?
Answer: The timeout property is set for the WCF Service client call using binding tag.

 

<client>

 

<endpoint

 

 

binding = “wsHttpBinding”

 

bindingConfiguration = “LongTimeout”

 

 

/>

</client>

<bindings>

<wsHttpBinding>

<binding name = “LongTimeout” sendTimeout = “00:04:00″/>

</wsHttpBinding>

</bindings>

If there is no timeout are specified, the considered default value is  1 minute.

117. Explain the WCF fundamentals and its architecture in brief.

Answer: The WCF framework is suitable to send asynchronous messages from one endpoint to another endpoint. This will use a set of APIs for exchanging messages between the server and the client. It will help in accessing apps over the internet whetherdifferent server or same server.

Fundamental of WCF is

  1. Interoperability
  2. Unification
  3. Service Orientation

WCF Architecture

The WCF architecture is made up of the Application Layer, Contracts, Service Runtime, Messaging, Activating, and Hosting layers.

118. What is the need for WCF services for business?
Answer: WCF services are use for following reason in business:

1.It is used for exchanging messages in the XML format with the help of HTTP protocol for maintaining interoperability.

2.WCF will use remote services for exchanging messages in binary format with the help of TCP protocol for maintaining the performance.

3.A service to exchange data are send securely over the network in the real -time.


119. Do web services come under SOA?
Answer: Web services do not come under SOA but it is standard for achieving the SOA.

120. What are the hosting requirements for a web service?

Answer: A WCF service will be self-hosting using a console application or Windows Forms applications. Following is Hosting Environment Requirements:

Availability: able to reach the service.

Reliability: If service somehow breaks, what will be affecting on other consumers?

Manageability:  Easy access to information about the host where WCF services live.

Versioning: Support for older version
Deployment: Type of deployment model. Either it is installed through the Microsoft Installer process or Visual Studio deployment packages.
State: Whether service is stateless.

121. What is the address formats of the WCF transport schemas?
Answer: Address format of WCF transport schema will follow

[transport]://[machine or domain][:optional port] format.

  Example:

  HTTP Address Format

http://localhost:8888

This is the way for reading the above url is

“Using HTTP, go for the machine called localhost, port 8888 someone is waiting”

When the port number will not be specified, default port is 80.

TCP Address Format

net.tcp://localhost:8888/MyService

When a port number will not be specified, default port is 808:

net.tcp://localhost/MyService

NOTE: Two HTTP and TCP addresses from the same host will able to share a port, even on the same machine.

IPC Address Format

net.pipe://localhost/MyPipe

We can only able to open a named pipe once per machine,  therefore this is not possible for two named pipe addresses for sharing a pipe name on the same machine.

MSMQ Address Format

net.msmq://localhost/private/MyService

net.msmq://localhost/MyService

122. How to configure Reliability while communicating with WCF Services?
Answer: Reliability will be configured in the client config file by adding reliableSession under binding tag.

<system.serviceModel>

<services>

<service name = “MyService”>

<endpoint

address  = “net.tcp://localhost:8888/MyService”

binding  = “netTcpBinding”

bindingConfiguration = “ReliableCommunication”

contract = “IMyContract”/>

 

</service>

</services>

<bindings>

<netTcpBinding>

<binding name = “ReliableCommunication”>

 

<reliableSession enabled = “true”/>

 

</binding>

</netTcpBinding>

</bindings>

</system.serviceModel>

Reliability is supported by below bindings

NetTcpBinding

WSHttpBinding

WSFederationHttpBinding

WSDualHttpBinding

 

123. What are the advantages and disadvantages of self- hosting?
Answer: The following are the advantages of self-hosting:

easy to use: With only a few lines of code, service can run.

flexible: Easily control the lifetime of  services by the Open() and Close() methods of ServiceHost<T>.

easy to debug: Debugging of  WCF services that are hosted in a self-hosted environment will provide a familiar way of debugging.  It will not need to attach to separate applications which activate service.

easy to deploy:  Deploying simple Windows applications is as simple as xcopy.

Supports all bindings and transports:  Self-hosting will not limit to out-of-the-box bindings and transports.

The following are the disadvantages of self-hosting:

Limited availability: The service can be reachable only when the application is running.
Limited features: Self-hosted applications can
only have limited support for availability, versioning, easy manageability, robustness, deployment scenarios and

recoverability.

124. How do we host a WCF service in IIS?
Answer: IIS hosting: To host a WCF Service in IIS (version    5 or 6), only the HTTP option is available as the transport protocol. In later versions of Internet Information Services (IIS), any other protocol (TCP/IP, MSMQ, NamedPipes and so on.)  can be used as transport protocol.
If a service is hosted under IIS then all the features of IIS like process recycling, ideal shutdown etc. Visual Studio will provide two different ways to host our WCF service in a local IIS in all are familiar with Publishing Wizard. The another way using Visual Studio only in a simple manner to host WCF service in local IIS.

To host the WCF services, follow below steps. The updated configuration for System.ServiceModel in the web.config is as follows:

<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name=”StudentServiceBehavior”>
<serviceMetadata httpGetEnabled=”true”/>
<serviceDebug includeExceptionDetailInFaults=”false”/> </behavior>

</serviceBehaviors>

</behaviors>

<services>
<service behaviorConfiguration=”StudentServiceBehavior” name=”StudentService.StudentService”>

<endpoint address=”http://localhost/StudentIISHost/MyStudentHost.svc” binding=”wsHttpBinding” contract=”StudentService.IStudentService”>

<identity>

<dns value=”localhost”/> </identity>

</endpoint>

<endpoint address=”mex” binding=”mexHttpBinding” contract=”IMetadataExchange”/> </service>

</services>

</system.serviceModel>

Configuring One Way Operation

Boolean ISOneWay property of OperationContract class is used for configuring service as one way service. It is required to set this property to true.

using System;

using System.Net.Security;

namespace System.ServiceModel

{

[AttributeUsage(AttributeTargets.Method)]

public sealed class OperationContractAttribute: Attribute

{

public OperationContractAttribute();

public string Action

{

get;

set;

}

public bool AsyncPattern

{

get;

set;

}

public bool HasProtectionLevel

{

get;

}

public bool IsInitiating

{

get;

set;

}

 

public bool IsOneWay

{
get;

set;

}

public bool IsTerminating

{

get;

set;

}

public string Name

{
get;

set;

}

public ProtectionLevel ProtectionLevel

{
get;

set;

}

public string ReplyAction

{

get;

set;

}

}

}
The client will not  do anything specific to invoke one way operation.

125. What is Transaction Propagation?
Answer: Transaction propagation is the ability for propagating a transaction across the boundaries of a single service. A service will participate in a transaction which is initiated by a client.

In a SOA environment, transaction propagation is a key requirement.  WCF will support SOA, therefore it provides support for transaction propagation as well.

To enable transaction propagation, we required to set the value of the TransactionFlow property of the binding being used.
This can be done programmatically as below:

1.WSHttpBinding bindingBeingUsed = new WSHttpBinding();

2.bindingBeingUsed.TransactionFlow = “true”;
Or it will be done by  updating the configuration file as follows:

<bindings>

<wsHttpBinding>

<binding name=”binding1″ transactionFlow=”true” />

</wsHttpBinding>

</bindings>

126. What is Tracing in WCF?
Answer: The tracing mechanism in the Windows Communication Foundation is based on the classes which reside in the System.Diagnostic namespace.
The important classes are following
1.Trace,
2.TraceSource
3.TraceListener

Configuring WCF for emitting tracing information/Define Trace Source, the following options are available:

  • ServiceModel
  • ServiceModel.MessageLogging
  • ServiceModel.IdentityModel
  • ServiceModel.Activation
  • Runtime.Serialization
  • IO.Log
  • Cardspace

Example

configuration>

<system.diagnostics>

<sources>

<source name=”System.ServiceModel”

switchValue=”Information, ActivityTracing”

propagateActivity=”true”>

<listeners>

<add name=”traceListener”
type=”System.Diagnostics.XmlWriterTraceListener”

initializeData= “c:\log\Traces.svclog” />

</listeners>

</source>

</sources>

</system.diagnostics>

</configuration>

127. What is Streaming in WCF?
Answer: In WCF, message will be buffered at the receiving side and after it is fully received it will get delivered to the receiving end. In this approach, receiver end remains unresponsive while message is getting buffered. It is fine for small size messages but this approach is not good for the large size messages therefore streaming will overcome this problem in WCF.

Streaming and Binding

1.TCP, IPC and HTTP bindings will support streaming.

2.By default, for all the Binding, streaming is disabled.

3.Streaming of the message must be enabled in the binding for overriding the buffering and enable the streaming.

4.TransferMode property must be set according to the desired streaming mode in the bindings.

5.TransferMode property is enum TransferMode

Configuring Streaming in Config file

<system.serviceModel>

<services>

<service name=”OneWayService.Service1″ behaviorConfiguration=”OneWayService.Service1Behavior”>

<!– Service Endpoints –>

<endpoint address=”” binding=”basicHttpBinding” bindingConfiguration=”StreamedHttp” contract=”OneWayService.IService1″>

<identity>

<dns value=”localhost” /> </identity>

</endpoint>

<endpoint address=”mex” binding=”mexHttpBinding” contract=”IMetadataExchange” /> </service>

</services>

<bindings>

<basicHttpBinding>

<binding name=”StreamedHttp” transferMode=”Streamed” /> </basicHttpBinding>

</bindings>

<behaviors>

<serviceBehaviors>

<behavior name=”OneWayService.Service1Behavior”>

<serviceMetadatahttpGetEnabled=”true” />

<serviceDebugincludeExceptionDetailInFaults=”false” /> </behavior>

</serviceBehaviors>

</behaviors>

</system.serviceModel>

128. What is the concept of tracelevel in trace listeners?
Answer: To enable the wcf trace it is required to mention the trace source in configuration file like Web.config. System.ServiceModel is Mostly and widely used trace source. Another trace source that is mostly used for WCF Message logging is System.ServiceModel.MessageLogging.

129. What are Information cards in WCF?
Answer: Information card is virtual representations of a person’s identity which are assured by a particular party. Information card is analogous to real-world identity card like passports, driver’s license, credit card, and employee ID card etc.
Information cards in WCF will provide more benefits than CardSpace.

Following is the Benefits of adding Information Card

  • Authentication
  • Authorization
  • Reduce IT pain
  • Granting trust to domains
  • Helps in maintaining security

Sample Code for showing the usage of DerivativesCalculator which will help in adding Information card that requires no external reference to do so.

namespace DerivativesCalculator

{

public class Calculator

{

public decimal CalculateDerivative(string[] symbols, string[] parameters, string[] functions)

{

return (decimal)(System.DateTime.Now > Millisecond);

}

}

}

1.Information card is more flexible than simple user name and password.

2.Information card will employ strong cryptography, that will make their use more secure than passwords.

3.Information card can potentially present any type of  identity claim which makes sense to all of the interacting parties and which user is willing to release.

130. What are the steps to optimise WCF service?
Answer: The steps to optimise WCF service
Step 1 : Choose the correct binding for WCF Service.
Step 2 : Choose the correct Encoding for  WCF Service.
Step 3 : Compress after Encoding
Step 4 : Choose the correct data Caching in  WCF Service.
Step 5 : Performance Optimization

131. What is WCF Service Impersonation and what all are the levels for Impersonation?
Answer: Impersonation is validated, if the client is authorised for requesting service.

Impersonation has following levels of settings.

  • Allowed : It will automatically impersonate the client whenever Windows authentication will be used. But it will not have effect with other authentication mechanisms.
  • Not allowed : This will indicate the service should not auto Impersonate.
  • Required : It will ensure, windows authentication is used else throw exception

132. What all are the new features introduced in WCF 4.5?
Answer: 1.Simplified Generated Configuration files on client can only have non-default binding configuration.

2.In v4.5, Validating WCF Configuration is added. Whenever compiling if there will be some validation errors with configuration file, it can be displayed as warnings in Visual Studio.

3.WCF 4.5 can support for Task-based Asynchronous programming model.

4.Contract First Development can be now supported. Only contract are generated in service.cs, if it is used SvcUtil.exe with “/ServiceContract” switch while generating proxy.

5.ASP.NET Compatibility Mode changed for enabling WCF service for participating in ASP.NET Pipeline such asASMX services.

5.Tooltip and intellisense will support in Configuration files.

6.XmlDictionaryReaderQuotas default values are changed.

7.v4.5 allows for creating an endpoint which will support.
8.WCF Service are configured using config file or through code. In v4.5, configuration through code are simplified by defining a public static method (i.e. configure) instead of creating a ServiceHostFactory.

133. What all are the impersonation options?
Answer: There are three options for impersonation:

  • Impersonating the original caller declaratively on specific operations. Use this option when you want to impersonate the original caller for the entire duration of a specific operation.
  • Impersonating the original caller declaratively on the entire service. Use this option when you want to impersonate the original caller for the entire duration of all operations in the service.
  • Impersonating the original caller programmatically within an operation. Use this option when you want to impersonate the original caller for a short duration in a service operation.

 

134. What is the difference between Impersonation and Delegation?
Answer: Impersonation will flow the original caller’s identity to back-end resources on the same computer. Delegation will flow the original caller’s identity to back-end resources on computers on which the service is not running.

135. What is constrained Delegation?
Answer: With constrained delegation, we configure the Microsoft Active Directory service for restricting the services and servers that WCF service application will access with the impersonated identity. Constrained delegation in Windows Server 2003 needs Kerberos authentication.

136. What is protocol transition?
Answer: Protocol transition is a Windows Server 2003 feature which will allow to switch from an alternate, non-Windows authentication mode to Kerberos authentication. This is useful when application does not use Kerberos authentication to authenticate its callers, and when application requires to use constrained delegation for accessing downstream network resources

137. What WCF service security events should be logged?
Answer:

  • WCF auditing to logging authorization successes and failures.
  • WCF message logging for logging malformed Simple Object Access Protocol (SOAP) messages.
  • NET health monitoring in conjunction with input and data validation routines for logging malformed parameters and schema in incoming WCF messages.

138. How do you implement log throttling in WCF?
Answer: We specify the maximum number of messages to log as well as the maximum size of the messages will be logged.

These attributes are found in the <messagelogging> element:

maxMessagesToLog. Allows to limit the size of the log file, by reducing the total number of messages in the log. This setting is used for reducing the chances of a denial of service (DoS) attack on log but will be used by an attacker to fill up the log and conceal their intrusion.

maxSizeOfMessagesToLog. Allows to limit the size of the log file, by restricting very large messages from being logged. This setting will be used for reducing the chances of a DoS attack on log but potentially can be used by an attacker to conceal their intrusion by ensuring which certain messages are not logged.

139. How do you protect your log files?
Answer: Log files can be protected using Microsoft Windows access control lists (ACLs) with restricted access.

140. How do you stop service if there has been an auditing failure?
Answer: Set the SuppressAuditFailure element to false to throw an exception, if there has been an auditing failure. By default, this is set to true, it means service continues running even after auditing are failed and no additional events are logged.

141. How do you implement health monitoring features in WCF?
Answer: To use the health monitoring feature in WCF, configure WCF service by following steps:

  1. A custom health monitoring event is created.
  2. Configure WCF service to monitor health.
  3. Instrument an application for raising a custom event.

144. What are the core security concepts supported by WCF?
Answer: Confidentiality: Confidentiality is confirming the recipient.
1. WCF will make sure that the valid recipient will read the message when it is passed between service and client.

2.Integrity: Integrity is for ensuring that message received has not being tempered or changed during process of exchange.

3.Authentication: Authentication is a way for the sender and receiver for identifing each other.

4.Authorization: It will ensure what actions an authenticated user can perform.

 143. Explain about authorization options supported in WCF?
Answer: Authorization is a core feature of security in WCF which supports different authorization types.
1.Role-based authorization is a common authorization approach which is used. In this approach, authenticated user are assigned roles, system checks and verifies that either a specific assigned role will be performed the operation requested.

2.Identity-based authorization approach is basically provide support for identity model feature which can be considered as  an extension to role-based authorization option. In this approach, service verifies client claims against authorization policies, accordingly grant or deny access to operation or resource.

144. What is Service host Factory in WCF?
Answer: Service host Factory is a mechanism in which we will create the instance of service host dynamically when the request comes in.

This is helpful to implement event handler for opening and closing the service.

145. What is Session Mode Enumeration in WCF?
Answer: SessionMode enumeration can be used with the service contract for allowing or restricting bindings to use sessions.

There are following ways for handling SessionMode enumeration.

1.Allowed

2.Not Allowed

3.Required

 

WCF (Windows Communication Foundation) is a popular framework in .NET community which extensively used to build the applications based on Service oriented architecture. The data can be asynchronously transferred between applications and within the application also using WCF. The modern day applications demand service based architecture for future scalability and easy maintenance. Hence, WCF is one of high demand skills in .NET world.  We compiled 145 most frequently asked WCF Interview questions with best answers, suggest you to go through above listed 145 WCF interview questions before attending your next job interview.

Share this: