WCF Interview Questions and Answers

    1 Votes

WCF Interview questions and answers for freshers and 2-3 year experienced C# .Net Programmers with examples

1) What is WCF ?

Microsoft has introduced WCF for inter process communication. WCF let us to establish communication channels using MSMQ, Remoting etc.
2) Explain the components used in WCF?
Below are the essential components of WCF –
  • Service class
  • End point
  • Hosting Environment
3) How WCF works?

WCF will follow – “Software and Service Model” , in which all essential components are defined as services and this will be used by client program.

4) Explain the difference between classic web services (ASMX) and WCF?

Classic webservice known as ASMX were using SOAP protocol for sending and receiving the messages over network and over HTTP protocol whereas WCF allows the communication to happen over any transport protocol.

5) What is Endpoint in WCF?

Endpoint will have following properties –

  • Address
  • Binding
  • Contract

6) Explain “Address” property of endpoint in WCF?

Address” property is the part of endpoint defined in service level and this property is used to determine the location if the service, where it is located.

7) Explain “Binding” property of endpoint in WCF?

Binding” property is the part of endpoint defined in service level and this property is used to decide out the type protocols, encoding's and transport. These all factors has been decided by both the parties who want to communicate each other.

8) Explain “Contract” property of endpoint in WCF?

It is just an interface between client and server where client and server communicate each other. Contracts are used to identify operations available.

9) Explain the types of contracts available in WCF?

Below are the list types of contracts available in WCF 

  • Data Contracts
  • Service Contracts
  • Message Contracts
  • Fault Contracts

10) Explain “Service Contracts” in WCF?

Service Contracts attribute given at the service level for WCF service and it will give you the list of operations that can be performed from that service. Service Contracts can be defined like –

[ServiceContract]

11) Mention the list of bindings supported by WCF?

Below are the list of schemas supported by WCF –

  • TCP
  • HTTP
  • MSMQ
  • IPC
  • Peer Network

12) Explain the ways to host the WCF Service?

Below are ways to host WCF Service –

  • IIS
  • Self Hosting
  • WAS

13) What is the Address format in WCF?

Below is the syntax of address –

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

14) What are duplex contracts in WCF?

Duplex contracts mainly uses duplex messaging which is used for callback to the client. Duplex messaging uses transport systems like – HTTP, TCP or Named Pipe.

15) What are different instance modes in WCF?

Below are the list of instance modes in WCF –

  • Per Call
  • Singleton
  • Per Session

16) Explain “Per Call” instance mode in WCF?

In “Per Call” mode, When a request has made to service, new instance of service will be created for each method call and this will be disposed once the response goes to client.

17) Explain “Per Session” instance mode in WCF?

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

18) Explain “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, instance will be created when service is hosted and it will be disposed once its shuts down.

19) What is Throttling in WCF?

Throttling” is used to limit the sessions or instances to be created at application level. And this will increase the performance.

20) What is the significance of “maxConcurrentCalls” in Throttling?

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

21) What is Service Proxy in WCF?

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

22) Explain Service Oriented Architecture?

Service Oriented Architecture is known as SOA. It is a design pattern where business functionality will be as a service and client will communicate to the service using proxy. Advantage of this will be – It is independent of platforms, vendor and product.

23) Why to use DataContarcts in WCF?

In WCF we can communicate with server from our client through 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 given at class level to serialize the class by using “[Datamember]” attribute over properties.

24) Mention types of transaction managers in WCF?

Below are the types of transaction managers –

  • WS- Atomic Transaction
  • Light Weight
  • OLE Transaction

25) Explain 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.

Eg: DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(MyTestClassType));

26) Explain XMLSerializer ?

This serializer was there from the beginning of .NET version. To serialize or deserialize an object just create an instance of XmlSerializer and pass the type of object. Methods – “Serialize()” or “DeSerialize()” methods used to serialize and deserialize objects respectively.

Eg: System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(MyTestClassType));

27) What are Operation Contracts in WCF?

Operation Contracts are the contracts between client and server on operations or methods which the service provides to the client. The methods used by the service are to be decorated by “[OperationContract]” attribute.

28) What are different modes of communication in WCF?

Below are the list of modes of communication between server and client –

  • One-Way
  • Request-Reply
  • Callback

29) Explain “Request-Reply” mode in WCF?

By default WCF works in this mode. When client made a request to a service, client will wait till it gets the response back to the client. If the response is not received till the given time, timeout error thrown. If client gets the response then next instructions will be executed.

30) What is the significance of “receiveTimeout” property in WCF?

This property is used to get/set the time interval that a connection remains active.


31) Explain “One-Way” mode in WCF?

In this mode client send a request to the server but does not wait till the response comes and does not care whether the request is failed or succeeded. Client will not blocked in this case till it receives the response.

32) Explain “Callback” mode in WCF?

This is the special mode of WCF where WCF on call back calls the method of client and in this scenario WCF service acts like a client and client acts like a service. But “HTTPBinding” does not support this mode we have to switch to “WSDualHttpBinding”.

33) What are Events in WCF?

Events allow the clients to get notified once it’s occurred in service side. Events will always result in direct call from client. Since service firing the event it’s called the publisher and since client is being notified about the event it is called subscriber.

34) What is the namespace used for WCF?

Namespace “System.ServiceModel” is used for WCF.

35) What are the isolation levels in WCF?

Below are the list of isolation levels in WCF –

  • Read Committed
  • Read Uncommitted
  • Serializable
  • Repeatable Read

36) List out Address format of all the bindings in WCF?

Below are the formats of address and its 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

37) What is WCF RIA?

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

38) How to generate proxy for WCF?

Proxy can generated from below steps –

  • Using Visual Studio
  • Using SvcUtil

39) Explain how to generate proxies using Svcutil in WCF?

SvcUtil is a command line utility. We can write the below command to generate proxy –

svcutil /t:code http://<mycreatedserviceurl>/out:<file_name>.cs /config:<file_name>.config

40) What you mean by “Transport Reliability” ?

Transport Reliability” meaning the guaranteed delivery of packets over network as protocol TCP does. It is not only the guaranteed delivery of packets it maintains the order of the packets as well.

41) What are default endpoints in WCF?

If service does not have any endpoints either in config or in program, by default WCF adds up one endpoint to the service created.

42) How to enable metadata information of the service?

Below are the 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.

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

Below are the list of bindings that are used for metadata –

  • mexHttpBinding
  • mexNamedPipeBinding
  • mexHttpsBinding
  • mexTcpBinding

44) What is the way to test our WCF application without creating client application?

Tool called - “wcftestclient.exe” used for testing the WCF service without creating a client application. We can open this tool from visual studio command prompt.

45) How to configure the reliability in configs file?

In config file we can use the tag of reliability as in the below code snippet –

<bindings>
<netTcpBinding>
<binding name = "MyTestBinding">
<reliableSession enabled = "true"/>
</binding>
</netTcpBinding>
</bindings>

46) Can overload methods in WCF? If Yes, How?

Yes we can overload operations or methods in WCF. Below is the sample code depicts the same –

[ServiceContract]
interface IMyTestCalculator
{
[OperationContract(Name = "AddTestInteger")]
int AddTest(int pararm1,int pararm2);
[OperationContract(Name = "AddTestDouble")]
double AddTest(double pararm1,double pararm2);
}

47) Explain Known Types in WCF?

If we define the complex complex class as the property of class would give a hard time for the compiler during deserilization process. So we will use attribute - KnownType to the parent class.

48) Give an example for KnownType?

Please check the below example for KnowTypes –

[KnownType(typeof(TestClassCar))]
[KnownType(typeof(TestClassTruck))]
[DataContract]
public class TestClassVehicle
{
}
[DataContract]
public class TestClassCar : TestClassVehicle
{
} [DataContract]
public class TestClassTruck : TestClassVehicle
{
}

49) Explain ServiceKnownType in WCF?

ServiceKnownType is used at Opeartion/Method level. When serviceknowntype is applied to the operation then that only operation will use known type.

50) Give an example for ServiceKnownType?

Below is the sample code snippet –

public Interface ITestVehicleService
{
[ServiceKnownType(typeof(TestClassCar))]
[ServiceKnownType(typeof(TestClassTruck))]

[OperationContract]
Vehicle AddNewTestVehicle(TestClassVehicle myVehicle);
[OperationContract]
bool UpdateTestVehicle(TestClassVehicle myTestVehicle);
}

51) What are Fault Contracts in WCF?

This contract is used to raise the error from service side or in simple words client will come to know about the service error from fault contract.

52) Write a code snippet for Fault Contract in WCF Service?

Below is the code snippet for fault contract –

public Interface ITestVehicleService
{
[ServiceKnownType(typeof(TestClassCar))]
[ServiceKnownType(typeof(TestClassTruck))]

[OperationContract]
Vehicle AddNewTestVehicle(TestClassVehicle myVehicle);
[OperationContract]
[FaultContract(typeof(VehicleFault))]
bool UpdateTestVehicle(TestClassVehicle myTestVehicle);
}
[DataContract]
public class VehicleFault
{
private string vehicle;
private string problemType;
[DataMember]
public string Vehicle
{
get { return vehicle; }
set { vehicle = value; }
}
[DataMember]
public string ProblemType
{
get { return problemType; }
set { problemType = value; }
}
}

53) What are Styles of models WCF supports?

WCF service supports 2 styles of models –
  • RPC style - In RPC-style we can use the serialize types and it provides the feature that are available for local calls.
  • Message style - Message style WCF allows the message header to be customized and it also allows us to define the security for body and header messages.
54) What are Message Contracts in WCF?

Message is the data which is passed from client to server and vice versa. WCF mainly uses SOAP protocol for sending these messages to and fro. Message Contract can be applied to the class and “MessageHeader” and “MessageBodyMember” attributes are used for custom body and header included in the message. (class)

55) What are the modes of sessions in WCF?
Below are the list of session modes in WCF –
  • Allowed
  • Required
  • Not Allowed
56) What is Durable Service?

These are WCF services which are used to persist the session state and its information even after client restarted the service host. It may use SQL for data storing state information.

57) How to implement Durable Services?

Durable services use “DurableService” attribute which can have attributes – “CanCreateInstance” and “CompletesInstance”.

58) Can we have two-way binding for MSMQ?

Yes we can have two-way bindings for MSMQ.

59) Explain dead letter queues?

Queue does not need to have a continuous connection between client and server. Message will be in queue once client or server puts some data into that and will stay till it has been picked up by client or server. In case that queue has not been picked within given timestamp then it will expire and is called dead letter queues.

60) How to track the service users?

Using “Parameter Inspector” extension we can track WCF service users. We can use methods like – “AfterCall” and “BeforeCall”.

61) How we can manage session in WCF?

Below are the ways to maintain the session in WCF –

  • Per Call
  • Per Session
  • Single

62) What are the main security features used in WCF?

Below are the features used to address security features –

  • Integrity
  • Confidentiality
  • Authentication
  • Authorization

63) What are the difference between transport level and message level security?

  • Transport Level Security – It happens at channel level. WCF uses transport like – TCP, HTTP, MSMQ etc. and each of these transports have its own security features.
  • Message Level Security – Here security is at the message level, while transferring the data to and from between client and server.

64) What is OData?

OData or Open Data Protocol is used to access the information exposed by data sources like SQL, Cloud Storage etc. using different clients like – browsers, BI, mobile etc.

65) Explain parts on OData?

Below are the main parts of Odata –

  • OData Data Model
  • OData Protocol
  • OData Service
  • OData Client Libraries

66) Can we call WCF service in Jquery?

Yes we can call WCF service in Jquery that is called WCF data service and this can be called from AJAX call.

67) What are transactions?

It is a group of operations which are executed in whole and it provides a way to logically group pieces and execute them at one shot.

Popular Videos

communication

How to improve your Interview, Salary Negotiation, Communication & Presentation Skills.

Got a tip or Question?
Let us know

Related Articles

C# Interview Questions
.Net Framework Interview Questions and Answers
ADO.Net Interview Questions and Answers for Freshers, Experienced
ASP.Net Interview Questions and Answers
ASP.Net MVC Interview questions and Answers
ASP.Net Web API Interview Questions
Top 50 Entity framework interview questions & answers