MCTS Windows Communication Foundation (WCF) 2 — Questions and Answers
Question 1: In WCF, which security mode encrypts and signs the message payload, protecting it regardless of transport-level security?
- Transport
- Message (Correct answer)
- TransportWithMessageCredential
- None
Correct answer: Message
Message security mode encrypts and signs the SOAP message itself using WS-Security, providing end-to-end protection independent of the transport channel.
Question 2: What is the purpose of the [DataContract] and [DataMember] attributes in WCF?
- To define service operations
- To mark a class and its fields/properties for serialization across service boundaries (Correct answer)
- To configure service throttling limits
- To specify which binding a service uses
Correct answer: To mark a class and its fields/properties for serialization across service boundaries
[DataContract] marks a type as serializable by the DataContractSerializer, and [DataMember] marks the specific fields or properties to include in serialization.
Question 3: Which WCF communication pattern allows the service to call back to the client, requiring the client to implement a callback contract?
- Request-Reply
- One-Way
- Duplex (Correct answer)
- Streaming
Correct answer: Duplex
Duplex communication allows the service to initiate calls to the client through a callback channel, which the client must implement as a separate contract.
Question 4: What does the ChannelFactory<T> class provide in WCF client-side programming?
- It hosts the WCF service
- It creates typed client channel objects without requiring a generated proxy class (Correct answer)
- It manages service throttling on the server
- It configures message encoding formats
Correct answer: It creates typed client channel objects without requiring a generated proxy class
ChannelFactory<T> allows you to create a channel to a service using a known contract interface, avoiding the need for a generated client proxy class.
Question 5: Which WCF binding is best suited for REST/JSON services consumed by web browsers or mobile clients?
- BasicHttpBinding
- WSHttpBinding
- NetTcpBinding
- WebHttpBinding (Correct answer)
Correct answer: WebHttpBinding
WebHttpBinding configures WCF for RESTful services using HTTP GET/POST with JSON or XML, without SOAP envelopes, suitable for browser and mobile clients.
Question 6: What is the role of an IServiceBehavior implementation in WCF?
- It defines the operations exposed by the service
- It customizes or extends the runtime behavior of the entire service (Correct answer)
- It specifies the transport protocol for the service
- It encrypts outgoing messages
Correct answer: It customizes or extends the runtime behavior of the entire service
IServiceBehavior allows you to inspect, modify, or extend WCF service runtime behavior such as adding inspectors, validators, or custom throttling.
Question 7: Which InstanceContextMode value causes WCF to create a new service instance for every incoming message?
- Single
- PerSession
- PerCall (Correct answer)
- Shared
Correct answer: PerCall
InstanceContextMode.PerCall creates a new service object for each incoming operation call, ensuring stateless, scalable request processing.
In WCF, which security mode encrypts and signs the message payload, protecting it regardless of transport-level security?