Windows Communication Foundation (WCF) Interview Questions
Below are a collection of Windows Communication Foundation (WCF) interview questions. They include questions on Windows Communication Foundation topics such as endpoints, contracts, attributes, signatures, bindings and contexts.
They are suitable for the following job roles:
- .NET Developer
- C# Developer
- Analyst Developer
- Web Developer
- .NET 3.5/4.0 Developer
We wrote these questions for other IT professionals to help them practice for their next interview or technical test. They are suitable for both consultants, temp staff or full time permanent roles.
If the organisation is using Windows Communication Foundation then these questions should help you out..
Interview Questions
1. You have created a new service based on Windows Communication Foundation and also a client application to test the service. You want add an endpoint in the web.config file of the client application to use the new service. Which values should you include in you service element of the web.config file?
Address
Contract
Binding
All of these
Show AnswerAnswer:
All of these
Comments:
Its good practice to use configuration file settings to provide flexibility at the time of deployment. The endpoint definition specifies an address, binding, and contract. The binding specifies transport and security details for how the service is to be accessed
2. A service contract specifies what an endpoint communicates to the outside world. At a more concrete level, it is a statement about a set of specific messages organized into basic message exchange patterns (MEPs), such as request/reply, one-way, and duplex. Which of the following is NOT part of the Service Contract specification:
The data types of messages
The specific protocols and serialization formats
The location of the operations
The frequency of messages per second
Show AnswerAnswer:
The frequency of messages per second
Comments:
The frequency of messages is not defined in the Service Contract specification. Services and consumers will depict the frequency of messages exchanged
3. Services are groups of operations. To create a service contract you usually model operations and specify their grouping. In Windows Communication Foundation (WCF) applications, developers define the operations by creating a method and marking it with the which attribute?
ServiceContractAttribute
DataMemberAttribute
DataContractAttribute
OperationContractAttribute
Show AnswerAnswer:
OperationContractAttribute
Comments:
The OperationContractAttribute Indicates that a method defines an operation that is part of a service contract in a Windows Communication Foundation (WCF) application
4. You’ve created a new class in your .NET project that contains a wide variety of operations grouped together to form part of a Server Contract. You now need to add an attribute to the class to define it as a service contract. Which attribute should you use?
OperationContractAttribute
DataMemberAttribute
DataContractAttribute
ServiceContractAttribute
Show AnswerAnswer:
ServiceContractAttribute
Comments:
The ServiceContractAttribute indicates that an interface or a class defines a service contract in a Windows Communication Foundation (WCF) application.
5. Both classes and interfaces represent a grouping of functionality and, therefore, both can be used to define a WCF service contract. However, it is recommended that you use interfaces because they directly model service contracts. Without an implementation, interfaces do no more than define a grouping of methods with certain signatures. Which of the following is a benefit of using interfaces to define Service Contracts?
Service contract interfaces can extend any number of other service contract interfaces.
You can modify the implementation of a service contract by changing the interface implementation, while the service contract remains the same
A single class can implement any number of service contracts by implementing those service contract interfaces.
All of these
Show AnswerAnswer:
All of these
6. You have created a new class which will be the basis for a Service Contract. You have used ServiceContractAttribute and OperationContractAttribute to decorate the class and the methods. Which of the following is NOT an advantage of using classes instead of interfaces for Service Contracts?
Speed
All of these are disadvantages
Simplicity
Multiple Inheritance
Show AnswerAnswer:
Multiple Inheritance
Comments:
Managed classes do not support multiple inheritance, and as a result they can only implement one service contract at a time. In addition, any modification to the class or method signatures modifies the public contract for that service, which can prevent unmodified clients from using your service
7. Which of the following is TRUE regarding service operations and references to objects?
Objects must be serializable
You can’t return values from service operations
Objects are passed as references
You can’t pass parameters to service operations
Show AnswerAnswer:
Objects must be serializable
Comments:
Service operations can pass values back and forth between client and service, but they are passed as copies not by reference. Each type used in a parameter or return value must be serializable
8. You’ve created a new class and decorated it with the DataContractAttribute so that it forms a Data Contract for WCF. This class contains several attributes that you want to make available as part of the Data Contract. Currently these attributes are declared as private. What do you need to do to ensure these attributes are serializable?
Add the DataMemberAttribute and change the type to public
Add the DataContractAttribute to the attribute
Change the type to internal
Add the DataMemberAttribute or change the type to public
Show AnswerAnswer:
Add the DataMemberAttribute or change the type to public
Comments:
Remember that all public types, including those without attributes, are serializable
9. A developer has designed a service that contains a method called TakeAction which is decorated with the following attribute:
[OperationContractAttribute(IsOneWay=true)]
Another client application will invoke the TakeAction operation and continue processing after WCF writes the message to the network. What must the developer of the TakeAction method do to ensure the client action can call this method?
Use object as the return type
Use FaultException as the return type
Remove all parameters from the method signature
Use void as the return type
Show AnswerAnswer:
Use void as the return type
Comments:
Setting the IsOneWay property to true means that the service operation does not send a return message and clients return immediately once the outbound message has been handed to the channel layer.
10. The signature of a service operation dictates a certain underlying message exchange pattern (MEP) that can support the data transfer and the features an operation requires. You want to adopt a pattern that supports the sending and receiving of messages by both the service and client. Which patter should you choose?
one-way
none of these
request/reply
duplex
Show AnswerAnswer:
duplex
Comments:
A duplex pattern is characterized by the ability of both the service and the client to send messages to each other independently whether using one-way or request/reply messaging. This form of two-way communication is useful for services that must communicate directly to the client or for providing an asynchronous experience to either side of a message exchange, including event-like behavior
11. Study the following line of code:
OperationContext.Current.GetCallbackChannel();
The ICalendarDuplexCallback interface is defined as the CallbackContract property in the Service Contract. In which class should you use this line of code?
Client
You should never use this
Both
Service
Show AnswerAnswer:
Service
Comments:
In the service's implementation of the primary contract, you should declare a variable for the callback interface. Then set the variable to the object reference returned by the GetCallbackChannel method of the OperationContext class (as shown above). You can then call any of the Clients methods defined in the Callback contract.
See: http://msdn.microsoft.com/en-us/library/ms731184.aspx
12. A client application interacts with a new Service that calculates interest rates for the banks customers. The Service Contract contains BasicHttpBinding as the binding type in the endpoint configuration. The service contains some methods that return sensitive information such as customers names and addresses. You want to ensure that these methods are encrypted. What should you do?
Set the ProtectionLevel to None in the ServiceContractAttribute
Set the ProtectionLevel in the OperationContractAttribute to EncryptAndSign for each of the sensitive methods
Nothing, all messages will be encrypted and signed already
Set the ProtectionLevel to Sign in the ServiceContractAttribute
Show AnswerAnswer:
Set the ProtectionLevel in the OperationContractAttribute to EncryptAndSign for each of the sensitive methods
Comments:
With BasicHttpBinding Security is turned off by default, but can be added setting the BasicHttpSecurityMode to a value other than None in the BasicHttpBinding(BasicHttpSecurityMode) constructor OR you can explicitly specify the protection requirements for your contract by setting the ProtectionLevel property of the to the level your service contract requires
13. Which of the following is FALSE regarding the WSHttpBinding class?
Provides WS-Addressing
Provides un-encrypted messages by default
Provides reliable messaging
Provides transactions
Show AnswerAnswer:
Provides un-encrypted messages by default
Comments:
WSHttpBinding represents an interoperable binding that supports distributed transactions and secure, reliable sessions
14. In Windows Communication Foundation (WCF) applications, which of the following is FALSE regarding Sessions?
Messages delivered during a session are processed in the order in which they are received
They are explicitly initiated and terminated by the receiving application
There is no general data store associated with a WCF session
Sessions correlate a group of messages into a conversation
Show AnswerAnswer:
They are explicitly initiated and terminated by the receiving application
Comments:
Sessions are explicitly initiated and terminated by the calling application
15. The instancing behaviour (set by using the System.ServiceModel.ServiceBehaviorAttribute.InstanceContextMode property) controls how the InstanceContext is created in response to incoming messages. You have created a new WCF service and set the InstanceContextMode to PerCall. What is the behaviour of the InstanceContext in this mode?
A new InstanceContext is created for each call
A new InstanceContext is created for each channel
A new InstanceContext is created for all calls
A new InstanceContext is never created
Show AnswerAnswer:
A new InstanceContext is created for each call
Comments:
When the mode is set to PerCall, a new InstanceContext (and therefore service object) is created for each client request.
16. When configuring a WCF service using Visual Studio, you can use either a Web.config file or an App.config file to specify the settings. The choice of the configuration file name is determined by the hosting environment you choose for the service. Where does the endpoint configuration element lie in a .NET configuration file?
System.ServiceModel – bindings – endpoint
System.ServiceModel – services – service – endpoint
System.ServiceModel – endpoint
System.ServiceModel – behaviors - behavior – endpoint
Show AnswerAnswer:
System.ServiceModel – services – service – endpoint
17. The System.ServiceModel.Channels namespace contains the DeliveryFailure enumeration. DeliveryFailure specifies the possible types of delivery failure for a message read from the queue. Which of the following elements is a valid DeliveryFailure?
All of these
BadSignature
AccessDenied
ReceiveTimeout
Show AnswerAnswer:
All of these
Comments:
You can get the DeliveryFailure property to determine why a message failed delivery and was sent to the dead-letter queue
18. Which class in WCF represents the unit of communication between endpoints in a distributed environment?
RequestContext
Message
Binding
ChannelBase
Show AnswerAnswer:
Message
Comments:
The Message class provides a means of communicating arbitrary information between a sender and a receiver on a network. It can be used to relay information, suggest or demand a course of action, or request data.