WCF(Windows Communication Foundation) is a technology or framework designed by Microsoft to develop SOAs(Service-Oriented Applications). It is used by every individual who uses the Windows Operating System. This blog discusses the most important and frequently asked WCF interview questions that an interviewer expects you to answer.
WCF is the unified programming model of Microsoft that we use to build service-oriented applications. It allows the .NET developers to develop reliable, secure, and transacted solutions that we can integrate throughout different platforms and collaborate with the existing ones. It allows us to communicate with Services, MS Messaging queues, and remoting in different ways.
WCF is a part of the .NET framework lifecycle, and the .NET framework is part of the lifecycle of the Microsoft Windows Operating System. So, as long as the Windows Operating System continues to function, the .NET framework and WCF will continue to function. Since Microsoft Windows is the most popular and widely used operating system, the demand for WCF Developers is massive. This blog includes all the WCF interview questions that help crack your WCF job interviews.
1. Define WCF?
2. Describe WCF Architecture and its basics?
4. Differentiate WCF and Web Services?
5. What are the Advantages and Features of WCF?
6. Explain SOA? Is web services SOA?
7. Explain the Service Contract?
10. Explain the Fault Contract?
Ans: WCF is the platform to develop distributed enterprises and deploy the services amid different endpoints in Windows. Initially, WCF was known as “Indigo”, and we offer interoperability and develop service-oriented applications. Windows Communication Foundation(WCF) is the programming model for creating service-oriented applications. We use WCF for deploying and creating that can be accessible to different clients.
It offers the environment where we can create the service accessible to windows clients and Linux clients or all the others. It offers more features in comparison to the web series.
If you want to enrich your career and become a professional in .Net, then enroll in ".Net Online Training" - This course will help you to achieve excellence in this domain. |
Ans: Windows Communication Foundation is the framework to build the service-oriented applications through which we transmit the asynchronous data/message from the óne service endpoint to another service endpoint. WCF is the runtime and group of APIs to create the systems that transmit messages between clients and services.
We use similar APIs and Infrastructure to create applications that interact with another application on a similar computer system or on the system that dwells in other companies and is retrieved over the internet. Following are some of the basics of WCF:
Architecture
WCF contains four main layers that offer developers the latest service-oriented programming model. Following are the layers of WCF architecture:
Ans: The Windows Communication Foundation is the framework for developing service-oriented applications. The majority of the WCF functionalities are covered in the Single assembly known as System.ServiceModel.dll, placed in System.ServiceModel namespace.
Need of WCF
Ans:
WCF: Through WCF, we can transmit the data as asynchronous messages from one service endpoint to another endpoint.
Web Services: The web service is the programmable application logic available through the standard web protocols. One of these web protocols is SOAP(Simple Object Access Protocol). SOAP is the W3C presented a note that utilizes standard-based technologies(HTTP for transport and XML for data description) for encoding and transmitting the application data.
Comparison Basis | Web Service | WCF |
Host | IIS can host the web service. | Windows Activation Service, IIS, Windows Service, and Self Hosting can host it. |
Model | The WebMethod attribute represents the method uncovered by the client. | The OperationContract attribute depicts the method revealed to the client. |
Programming | We should add the WebService attribute to the class. | We must add the ServiceContract attribute to the class. |
XML | We use System.Xml.Serialization namespace for serialization. | We use System.Runtime.Serialization namespace for serialization. |
Operation | Web Service supports different operations like Request-Response and One-way. | WCF supports operations like Duplex, One-way, and Request-Response. |
Transports | We can access Web Services using TCP, Custom, and HTTP. | We can access WCF using TCP, HTTP, MSMQ, pipes, Custom, and P2P. |
Encoding | MTOM(Message Transmission Optimization Mechanism), XML 1.0, Custom, and DIME. | Custom, XML 1. O, Binary, and MTOM. |
Protocols | Security | Reliable Messaging, Transactions, and Security. |
Ans: WCF(Windows Communication Foundation) is the reliable, scalable, and secure messaging platform for the .NET platform 3.0,
Related Article: Learn .Net Libraries |
Following are the Advantages of WCF:
It includes JSON and AJAX Integration support:
Ans: SOA refers to service-oriented architecture. The service-oriented architecture is the architectural methodology in software development where we organize the application as services.
The services are the set of methods that include business logic for connecting the DB to other services. For example, if we go to the hotel and order the food, first our order goes to the counter, and next it will go to the kitchen where food is prepared, and lastly, the waiter serves food.
Following are some essential characteristics of service-oriented architecture:
SOA Introduction: The Service-Oriented Architecture relies on the four crucial abstractions:
Application Front End: Application Front End is disconnected from services. Every service has a contract that specifies what it can do and multiple interfaces for implementing the contract.
Service Repository: Service Repository offers the home for services, and the service bus offers the mechanism to connect and interact with services.
A Service: It contains the methods with the specified contracts and business logic implementation for connecting DB to other services.
Is all web-services SOA?
SOA is the architectural idea, and web services are the technical approach for completing it. Web Services are the favoured standards for achieving SOA.
Ans: A service contract indicates the collective mechanism through which the service requirements and capabilities are defined for its customers. It specifies operations that the service performs when implemented. It tells the things about the service like operation locations, message data types, protocols, and clients we require for interacting with the service.
For creating the service contract, we define the interface with the associated methods, delegate the collection of the service operations, and next ádorn the class or interface with the “ServiceContract” attribute for indicating that it is the service contract. The methods in the interface that must be covered in the service contract are adorned with the “OperationContract” attribute.
Service Contract Attribute: We use it for declaring the type as the service contract. We can declare it without any parameters, yet it can take the named parameters.
Ans: The primary purpose of Contracts is to enable the services and client to agree to the kinds of structures and operations they will utilize in the transmission process. It displays the conventional agreements between service and client for specifying the Platform-neutral and typical to explain what the service performs. Following are the kinds of contracts:
It specifies the operations that the service reveals to the world outside. The service contract is defined as the interface of WCF service and tells the world outside what a service can perform. It can have service-level settings like service name and service namespace.
The operation contract specifies the method revealed to a client for exchanging information between the client and server. The operation contract explains what utility is provided to the client, like addition, subtraction, etc.
Data Contract specifies the data types and variables similar to set and gets parameters. Yet, the variance is that the Data Contract in the WCF is utilized for serializing and deserializing the data. It specifies how we serialize and deserialize the data types. We can transform the object into a series of bytes that we can send over the network through the serialization process. We can reassemble the object from the sequence of bytes we receive from the calling application through de-serialization.
When the operation contract has to transmit the message as the parameter or the return values as the message, the type of this message can be defined as the message contract. The message contract specifies the message elements(Message Body, Message Header) and the message-relevant settings like message security level. The message contracts offer you full control of SOAP header content and SOAP body structure.
The Fault Contract Specifies the errors generated by the service and how the service propagates and handles faults to its clients. The operation contract may have multiple contracts related to it.
Ans: The data contract is the official deal between a client and a service that abstractly explains the data to be interchanged. The data contract may be implicit or explicit. Simple data types like string, int have the implicit data type. User-defined objects are a complex or explicit type for which we have to specify the data contract through [DataMember] and [DataContract] attributes.
We can define the data contract in the following way:
Ans: Fault Contract offers the documented view of the error granted in our service to the client. This allows us to identify what error has happened and where quickly. When we throw the exception from the service, the error will not go to the client side.
The lesser the client knows what occurred on the client side, the greater unrelated the transmission will be; this is called error masking. Generally, all the exceptions are thrown onto the service side always go to the client as the FaultException. By having all the service exceptions interchangeable, WCF outcouples the client from the service.
Ans: Endpoints offer the configuration needed for the interaction and generate the entire WCF service application. The endpoint is the part of the information that teaches WCF to develop runtime communication channels for sending and receiving messages. The endpoint contains three things like address, contract, and binding.
All the interactions with the WCF(Windows Communication Foundation) service happen using service endpoints. Endpoint offers clients access to functionality provided by the WCF service. Every Endpoint contains four properties:
Structure of Endpoint
Every Endpoint includes the following:
Ans: Binding explains how the client will interact with the service. We have various protocols for WCF for communicating with clients. We can cite the type of protocol as per our requirements. Binding has various characteristics, containing the following:
Following are some of the protocols of WCF binding:
Binding | Description |
BasicHttpBinding | It is a fundamental Web service communication. By default, No security. |
WSHttpBinding | Web services with the WS-* support. It supports transactions. |
WSDualHttpBinding | Web Services with transaction support and duplex contract. |
WSFederationHttpBinding | Web Services along with the federated security. It supports transactions. |
MSMQIntegrationBinding | Communication directly with the MSMQ applications. It supports transactions. |
Ans: The transaction is the rational unit of work containing different activities that should either fail or succeed together. For instance, if we attempt to make the online purchase for the mobile, your amount will be drawn from the bank, yet your ordered mobile was not sent to you. So what did you understand from the prior sample?
Bank operations are done in individual services, and online purchase service is swarmed as another service. The online purchase did not do well as anticipated for the earlier sample because of a database query error. Without realizing it, the bank activities were accomplished successfully. We require transactions to assure that any operations must fail or succeed. Following are the kinds of Transactions:
WCF Transaction Phases
WCF Transactions have two phases:
Related Article: .Net Interview Questions and Answers for Beginners |
Ans: The Address is the Uniform Resource Locator(URL) that recognizes the location of the service. It specifies the network address to send and receive the messages. It is divided into four parts:
In WCF, each service is related to a unique address. The address offered two external elements like the location of the services and transport service that will help us interact with services. WCF supports the below transport schemas. WCF supports the following transport protocols:
An address will have the below format:
[transport]://[domain or machine][: optional port]
Example:
http://localhost:82/MyService
Ans: The WCF service may be self-hosting through the Windows Forms applications or console applications. Hosting the application in any .NET application is known as self-hosting. Follow the below procedure to create a WCF service and host it in the console application. Requirements of Hosting Environment:
We have the following options to host a WCF service:
Ans: A Service is defined as the application or program that other applications use. In simple words, the service utilized by end-users for doing their work is something they ask for and recognize.
WCF(Windows Communication Foundation) is introduced in .NET 3.0. This is a good network distributed system designed by Microsoft for interaction between the applications. WCF is suitable for developing and deploying the distributed applications below the Service-Oriented Architecture Implementation.
From the WSDN, WCF is the component of the .NET framework that offers the unified programming model for quickly developing service-oriented applications that interact throughout an enterprise and the web. WCF is the integrated feature of the web service, MSMQ, COM+, and Remoting.
Following are the three main elements of the WCF application:
Every endpoint includes:
Ans: We have a project, and we have to locally host one WCF service in this solution. This kind of host is known as Self-Hosting. To implement self-hosting, we have to include the “System.Service.Model.ServiceHost” namespace to implement self-hosting. Advantages of self-hosting are
Disadvantages of Self Hosting are
Ans: If we want to host the WCF service in IIS, only HTTP is available as the transport protocol. In the subsequent versions of IIS(Internet Information Services), we can utilize other protocols(MSMQ, NamedPipes, and TCP/IP) as the transport protocol.
If we host the IIS service, we include every feature of IIS like ideal shutdown, process recycling, etc. Visual Studio offers two ways to host a WCF service in the local IIS in all the usual methods with a publishing wizard. We will discuss another method of easily using Visual Studio for hosting our WCF service in the local IIS. We should follow the below steps for hosting the WCF services:
Ans: When the operation contains no return value, the client ensures the failure or success of invocation. WCF provides one-way operations for supporting this kind of fire-and-forget invocation. Once the client publishes the call, no interconnected reply message will return to the client. One-way message interchange is helpful when the client has to send the information for the service but does not receive a response. We utilize the one-way design pattern:
For creating the one-way service contract, we specify our service contract, implement the “OperationContractAttribute” class to every operation, and fix the “is one-way” property to true, as displayed in the below sample code:
Ans: WCF offers a message-oriented programming framework. We utilize WCF for transmitting messages between the applications. Implicitly WCF depicts every message using the message class. When the WCF sends the message, it takes the logical message object and encrypts it into a series of bytes.
Then WCF studies those bytes and decrypts them in the logical object. The mechanism builds a series of bytes into the logical object; this is known as the encrypting process. When the WCF ‘gets the local message at the runtime, it converts them into the corresponding .NET objects. This mechanism is known as serialization.
WCF has three fundamental serializers:
WCF deserializes the WCF messages into the .NET objects and serializes the .NET objects into the WCF messages. By default, WCF offers the “DataContractSerializer” with the service contract. We can modify this default serializer to a custom serializer like the XMLSerializer.
XMLSerializerFormat attribute on “ServiceContract” indicates the serializer is all the operation contracts. We can also fix a separate contract for every operation.
XMLSerializer: We may discover the XMLSerializer in System.Xml.Serialization namespace. WCF endorses the serialization from the .NET 1.0. By default, it is utilized with ASP.NET web services.
DataContractSerializer: The DataContractSerializer is the default serializer for the WCF. We don’t need to note the “DataContractSerializer” attribute above the service contract.
NetDataContractSerializer: The NetDataContractSerializer is similar to the .NET Remoting Formatters. It applies the IFormatter, and it is coherent with the Serializable types. It is not suitable for a service-oriented design.
Ans: There may be requirements where the operation of the service is not returning any value. At the same time, the client does not care about the failure or success of the service. The client will call the service and operation and forget and continue with operations.
One-way operations: In WCF, this is the best way to acquire Fire and Forget Invocation of service. WCF creates the request message when the client issues a call and has no equivalent response message. No Service side-exception will choose their way to the client.
Configuring One Way operation: “ISOneWay” property of the “OperationContract” is utilized for configuring the service as a one-way service. We have to set this property to true. Setting this property to true spins the service operation as a one-way operation. The client has no connection with calling one-way operation.
Ans: Transaction Propagation can propagate the transaction throughout the limits of a single service. In another way, the service can participate in the transaction that the client starts. In the SOA environment, transaction propagation turns into an essential requirement. WCF endorses SOA; thus, it also offers support for transaction propagation.
To facilitate transaction propagation, we have to fix the value of the transaction property of the binding being used. We can do this programmatically as follows:
Or we can do it elaborately by updating the configuration file as below:
Ans: WCF Throttling offers a few properties that we can utilize for restricting how many sessions or instances are generated at the application level. We can improve the performance of the WCF service by creating the proper instance.
Throttling of the services is an important component of WCF performance tuning. The WCF throttling offers the prosperities maxConcurrentInstances, max concurrent sessions, and max concurrent calls, which can enable us to restrict the number of sessions or instances generated at the application level.
Property/Attribute | Description |
maxConcurrentInstances | This defines the utmost amount of instances of the context object that implements at a time with service. |
maxConcurrentCalls | This defines the utmost number of messages refined throughout the service host. The default value of this property is 16. |
maxConcurrentSessions | This defines the utmost amount of sessions at once in the service host object. 10 is the default value. |
Ans: In WCF, a Simply Proxy or Service Proxy allows applications to communicate by receiving and sending messages. Basically, it is the class that binds the service details like service execution technology, service path, communication protocol, and platform. It includes every method of the service contract.
The client application utilizes a WCF client proxy for communicating with the service. Generally, client applications import the service metadata for creating the WCF client program that we can use for invoking service.
The fundamental steps to creating the WCF client: Compile the service code. Proxy offers similar operations as the service contract, yet also offers other methods to manage the proxy life cycle and connection to service. Proxy includes the data of service like Binding, Configuration, and address such that the client can communicate with the service. What security policies do we have to obey and whatever is prescribed by the service for working correctly?
Ans: WCF Concurrency indicates, “Various calculations are executing concurrently.”
WCF Concurrency allows us to configure how the WCF service instances may assist multiple requests simultaneously. We will require WCF concurrency due to the following reasons; there can be reasons, yet these are considered the important reasons:
We can utilize the parallel feature in the below three ways:
1. Single: The Single thread processes a single request on the server at any moment. The client proxy transmits the request to the server; it processes that request and takes another request. Concurrency. Single declaration:
2. Multiple: Multiple threads will process more than one request on the server at any moment. The client proxy transmits the request to the server. The server will process those requests by generating multiple threads on the server object.
3. Reentrant: Reentrant concurrency mode is similar to the single concurrency mode. It is the single-threaded service instance that accepts requests from the client proxy, and it releases the thread once the reentrant object invokes another service or invokes the WCF client using a callback.
Related Article: Introduction to .Net FrameWork? |
Ans: Exception handling is essential for all applications to troubleshoot unusual problems in the applications. The Windows Communication Foundation(WCF) offers various options to handle the exceptions in the WCF services. Following are the options to handle the exceptions:
Exception in a WCF
Example:
Ans: Representational State Transfer(REST) is a protocol to exchange data in a distributed environment. The fundamental idea behind the REST is that you must handle your distributed services as the resource, and you must utilize HTTP protocols for performing different operations on that resource.
JSON
JSON(JavaScript Object Notation) originated from Javascript programming language characters. It allows us to exchange and display the data independently, self-descriptive, and easy way. The data can be utilized and converted into javascript objects.
In almost every web-based application, we can consume WCF through Javascript, AngularJS, jQuery, etc. When the client invokes WCF, XML or JSON is utilized in communication. WCF contains the options for sending responses in the JSON object. We can configure it with WebInvoke or WebGet attribute and WebHttpBinding. This enables us to reveal the Service Contract as the REST service that we can invoke through either XML or JSON.
Ans: In WCF, the tracing process is on the basis of the classes that exist in the “System.Diagnostic” namespace. The elementary classes are called Trace, TraceListener, and TraceSource. We have the below options for configuring the WCF to eject the tracing information or Define the Trace Source:
Following are the essential steps of WCF Tracing:
Set Trace Level:
Ans: The KnownType Attribute class enables us to define the types that must be covered for attention in the deserialization. Generally, WCF service receives and returns a base type; if we anticipate the service for receiving and returning the inherited type next, we utilize the known type attribute.
When sending the parameters and returning the values between a service and a client, both endpoints, if we anticipate the service to receive and return the inherent type, we utilize the known type attribute.
While sending parameters and returning the values between the client and the service, both endpoints share every data contract of data to be sent.
Ans: Binding explains how the client will interact with the WCF service. We will use the binding according to the client's requirements. It endorses different protocols for communicating with the client and various encryption protocols for transferring the data on the internet. Thus, fundamentally binding is an approach of interaction between service and client according to the client’s requirements.
Basic Binding: Basic Binding is offered by BasicHttpBinding class. Basic Binding is developed for revealing the WCF service as the ASMX web service, such that the earlier clients can utilize the new service. Generally, it utilizes the HTTP protocol for transport and encrypts the message in the UTF-8 text format. We can also utilize HTTPS using the basic binding.
Web Service Binding: Web Service Binding is offered by the WSHttpBindingClass. It is similar to the fundamental binding and utilizes HTTPS or HTTP protocols for transport. Yet this is developed to provide different WS - * specifications like WS - Transactions, WS - Reliable Messaging, and WS - Security, which are not endorsed by the basic binding.
wsHttpBinding = basicHttpBinding + WS-*specification
Web Binding: Web Binding is offered by WebHttpBinding class. Web Binding is developed to reveal the WCF services as the HTTP requests through HTTP-POST and HTTP-GET. We use it with REST-based services that can offer an output in the JSON or XML format. This is very much required with social networks to implement a syndication feed.
TCP Binding: TCP Binding is offered by NetTcpBindingClass. It utilizes the TCO protocol for interaction across two machines in the Intranet. It encrypts the message in binary format. It is a more rapid and reliable binding in comparison to HTTP protocol bindings. TCP Binding is utilized only when the interaction is a WCF-to-WCF which indicates both service and client must have WCF.
The “NetMsmqBinding” class offers MSMQ Binding. It utilizes the MSMQ for transport and supports the disconnected message queued. It gives solutions for the disconnected use cases in which the service handles the message other than the client.
IPC Binding: IPC Binding is offered by NetNamedPipeBinding class. It utilizes the named pipe for interaction between two services on a similar machine. This is the most rapid and secure binding among all the bindings.
Ans: The “basicHttpBinding” is utilized to offer support for the older clients that anticipate an inherent ASMX web service. The “TransportCredentialOnly” security mode option sends the user credentials without signing or encrypting the messages.
BasicHttpBinding is ideal for interaction with the ASP.NET Web Service(ASMX) based services affirming the WS-Basic profile that affirms the web services.
Use the below procedure:
Ans: The Instance Context specifies how long the service instance resides on the server.
Request-Response Cycle
Every time the client transmits the request to the WCF service, what takes place backstage? Generally, after the client request, the WCF service creates the service class instance at the service that makes the operations engaged and next, it will return a response to the client. The process service instance object has been generated in this response and request.
WCF Framework defines the below Instance Context Modes:
PerCall: The latest instance of the service can be generated for a request from a different client or the same client, indicating all requests are the latest requests. In the PerCall mode, no state is retained. In the per-call service, all the client requests acquire the latest committed service instance, and the memory utilization is less in comparison to other kinds of instance activation.
Per-Session Service: We create the new instance for every new session, and that object scope will be that session scope.
Singleton Service: We create a single instance for a service object that looks after every request from the same client or a different client.
[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]
Ans: WCF supports various protocols like MSMQ, HTTP, and TCP; the user should take the required steps to secure our messages and define security policies to protect messages for authorising and authenticating the calls. WCF offers a vibrant and simple configurable environment to implement security. WCF supports the below securities:
Ans:
Comparison Basis | WsHttpBinding | BasicHttpBinding |
Compatibility | This is reckoned on the clients who do not install the .NET 3.0, and it endorses a broader range of clients. Most clients, such as Windows 2000, do not execute the .NET 3.0. Thus, the earlier version of the .NET can utilize this service. | Since it is developed through WS-* specifications, it will not support the broader range of clients, and the former .NET versions that may not utilize it less than the 3rd version. |
Security Support | This reveals the web services through WS-* specifications. | This supports the old ASMX style, WS-BasicProfile 1.1. |
Reliable Messaging | Supported since it supports the WS-* specifications. | Not Endorsed. In other terms, if the client discharges two or three calls |
SOAP Version | SOAP 1.2 | SOAP 1.1 |
Default Security Options | Since the WsHttpBinding WS-*, it includes the WS-Security activated by default. Thus, the data is not transmitted as plain text. | By default, messages do not have security when the client calls. Conversely, data is not transmitted as plain text. |
Security Options |
|
|
The most significant difference is the security aspect. By default, BasicHttpBinding transmits the data in plain text, while WsHttpBinding transmits it in a secured and encoded manner.
Ans: In the WCF, any message ís transmitted only after the entire message is transmitted. It indicates that the first message is buffered at the recipient side, and after it is wholly obtained, it gets transmitted to the receiving end.
The primary difficulty with this process is that the recipient end is unresponsive while buffering the message. Thus, the default method of binding message handling is suitable for the small messages, but for the big messages, this process is suitable. Therefore, to suppress this difficulty, Streaming is introduced.
Configuring the Streaming in the Config file:
Streaming and Binding
Ans: The objective of Transport Level Security is to provide privacy, authentication, and integrity. Following are the Advantages of Transport Level Security:
Transport Level Security Offers:
Ans:
Message Pattern: The message in the WCF is the same as the messages in real time.
It explains how the programs to interchange with each other. It has three methods of communication between destination and source. We don’t need to invoke a Java class from the C# class. When the programs have to communicate with each other, they send messages to each other.
Although it is acceptable to communicate through messages, we must normalize those messages. Next, when people want to exchange the data between the two programs, they receive the normalized message to accomplish it.
SOA is an architectural approach where two non-compliant applications can interact through a general language, and WCF is an example of SOA(Service-Oriented Architecture). Following are the SOA characteristics:
Ans: MEP refers to Message Exchange Patterns. In the WCF, we will create the services. What will the service do for us? Service does specific tasks to support us or transmit the response from the request. All those communications are carried out through messages. We transmit some messages as requests and get the message in the form of a response from the service. WCF has three kinds of Message Exchange Patterns(MEPs):
One-Way: Fix the IsOneWay property of the OperationContractAttribute to true for the OneWay message exchange pattern. We use the One-Way message exchange pattern when the service performs certain operations, and we do not need a response back. For instance, if we have to modify the transaction status from pending to finished and we do not need to obtain validation from service, that status is modified. We can utilise the OneWay pattern.
Request / Response: Request / Response is a quite common MEP. For setting this pattern, we have to set the IsOneWay property of the OperationContractAttribute as false. The default value of the IsOneWay property is false. Thus eventually, we do not have to set this property. By default, it is set. For this reason, it is effortless to implement.
Duplex: Duplex is the two-way message medium. When the client transmits the message to the service to demonstrate long-run processing and needs notification from the service, the duplex MEP is suitable.
We have two kinds of contracts, CallbackContract and ServiceContract, needed to implement the duplex MEP. The MEP is specified by relating a CallbackContract to ServiceContract. It is performed using the CallbackContract attribute of the ServiceContract.
Ans: The Instance mode is the service side execution. It must not display on the client side. The WCF specifies behaviors. Behaviour is the local property of the client or service that will not impact the interaction. The client hardly knows about service behavior and will not display service binding and published metadata. Following are the different Instance modes of WCF:
1. PerCall
When a service installs PerCall, each client obtains the latest service instance. The following diagram tells how the PerCall instance works:
2. PerSession Service
WCF supports the logical session between the service and client in the Precession instance mode. We create a new instance for every client. The below diagram depicts the request from client through Persession service instance mode:
Single Instance Service
When we set the service as a singleton, every client is linked to the single instance context. We install the singleton service by setting the InstanceContextMode property to single. This instance belongs to the service. We create another instance only by resetting IIS or when the service host is turned off.
When you must use per session, single-mode, and per call?
Per Session
Single Mode
Per Call
Ans: MSMQ(Microsoft Messaging Queue) is utilised for asynchronous interaction through messages. We can consider MSMQ as an inter-process communication capability. Whenever two processes need to interact with each other in the “Fire and Forget”, MSMQ is helpful for that.
Example: For instance, if the billing software requires executing more than 1000 bills at midnight and should send mail to all those users. When the operator uses the software, he requires immediate notification. The operator cannot wait for every bill to be processed and gets mail.
MSMQ plays an essential role in interaction by the billing software for sending those 1000s of the customer email information into the queue, and the Queue event handler handles the requests. The operator obtains immediate notification of processes rather than learning the “Behind the Scene” process.
Ans: Method Overloading is the feature that enables the generation of multiple ways with similar names. Yet, every method must vary from another in the output and input of the functions. All the methods should have different data types of parameters, whether they should vary in the amount of the parameters or the kind of parameters.
We can also consider Method Overloading as the run-time polymorphism as the invoking method knows the address of the called method, and the method addresses are fixed at run time. This is also called Early Binding.
Ans: Duplex is defined as a two-way communication mechanism. In Duplex, the consumer sends the message to the service, and the service transmits the notification that request Processing is performed. It is the same as that we pass the command to print the papers in the printer machine. The printer machine begins the communication by building the link with the machine and begins printing the printer.
We require the Message Exchange Pattern when:
Ans: The message layer is made up of channels. The channel is an element that executes the message in a particular methodology. Channels are the essential abstraction to send messages and receive messages from the endpoint.
Ans: For enabling the trace, we require to refer to the trace source in the configuration file, such as Web.config. “System.ServiceModel” is the frequently utilized trace source. For Message logging, we use the “System.ServiceModel.MessageLogging” as the trace source. WCF tracing offers the following tracing levels:
Index.no | Trace Level | Category of Event | Tracing Description | Traced Events |
1 | Important | Negative Event | Sudden events or error conditions. Once this happens, the application can turn off immediately or shortly. |
|
2 | Off | No Tracing. | Tracing is Ignored. | |
3 | Warning | Negative Events. | It indicates the feasibility of the problems. The application stays up and persists in the processing. |
Traces every problem that happened or may happen:
|
4 | Error | Negative Events | Unforeseen events or any error condition. When the application does not turn off, it stays up and persists in processing. | Trace all the exceptions. |
5 | Verbose | Positive Events | Similar to the “Information”, the only variance is that it enables low-level tracing. | Widely utilized for debugging. |
6 | Information | Positive Events | Only Informative traces that says the successful landmark of application execution. | It traces all the diagnostic data. |
7 | All | Negative & Positive | It contains all the above events. | It contains all the above events. |
8 | ActivityTracing | The traces are associated with the communication between components and activities. |
Ans: The fault exception is a method to manage the error or exception in WCF. In the C#, we can manage the error through try and catch blocks on the client side. We use the fault exception to manage the error through the service class and present it on the client side. Whenever the client invokes a service class, a sudden exception comes like Divide by Zero, or SQL Server is not responding. In this case, the service class throws the exception to the client through fault exception.
Generally, when we throw an exception from the service, it will not go to the client. WCF gives the option to manage and tell the error message to the client from the service through the SOAP Fault Contract. For supporting the SOAP Faults, WCF offers the FaultException class. This class includes two forms:
Syntax:
[OperationContract]
[FaultContract(typeof(MyException))]
String getDetails(int value);
Ans: Instance Management is defined as the group of techniques utilized by the WCF for binding the client requests for the service instances and administering the service instance that manages the client request.
Instance Management is the technique to determine which service instance will host the client's request. It also determines when the service instance will serve the client’s request. Instance Management is an essential factor while designing the service. It impacts:
Instance Management is considered the group of techniques for determining which service instance will host the client request and when. Fundamentally, we have the following Instance Modes:
Why do we require Instance Management?
We require Instance-Management since applications vary excessively in their requirements for scalability, throughput, performance, queued, and transaction calls. Thus, a single solution for all the applications does not suit.
Ans: Since we are utilizing the DerivativesCalculator sample for improving the WCF application, thus we can utilize it for adding the Information Card to the WCF application. Information Cards offer more advantages than CardSpace. Advantages of adding the Information Card:
The Information card is the virtual representation of the individual’s identity that is ensured by a specific party. The Information Cards are similar to real-time identity cards like credit cards, driver’s licenses, passports, and employee cards.
Ans: We use the Message Contract to control the message body's structure and serialization process. We also use it for sending or accessing the information in the SOAP headers. By default, WCF looks after creating SOAP messages as per the service DataContracts and operation contracts.
The MessageContract restraints the message body structure and serialization process. We can type or untype the MessageContract, and it is helpful in compatibility cases and when there is an available message format. We must obey it.
We implement the SOAP header in the namespace System.web.services.protocol
Message Header: The message header is applied to the member of the message contract for declaring the member in the message header.
Message Body Member: The message body header is implemented on the member of the message contract for declaring the members in the message body.
These WCF Interview Questions covered all the real-world scenarios and concepts of WCF. I hope these questions are sufficient to prepare for your job interviews. If you have any queries, let us know by commenting below.
Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:
Name | Dates | |
---|---|---|
.NET Training | Nov 19 to Dec 04 | View Details |
.NET Training | Nov 23 to Dec 08 | View Details |
.NET Training | Nov 26 to Dec 11 | View Details |
.NET Training | Nov 30 to Dec 15 | View Details |
Madhuri is a Senior Content Creator at MindMajix. She has written about a range of different topics on various technologies, which include, Splunk, Tensorflow, Selenium, and CEH. She spends most of her time researching on technology, and startups. Connect with her via LinkedIn and Twitter .