MCSD Windows Communication Foundation (WCF) 2 — Questions and Answers
Question 1: Which attribute marks a class as serializable for transfer in WCF messages?
- [Serializable]
- [DataContract] (Correct answer)
- [MessageContract]
- [KnownType]
Correct answer: [DataContract]
[DataContract] marks a class as a data transfer object whose members decorated with [DataMember] will be serialized by the DataContractSerializer.
Question 2: What is the purpose of the [KnownType] attribute in WCF?
- Marks an operation as a known service operation
- Declares derived types that the serializer should recognize for polymorphic serialization (Correct answer)
- Specifies the known bindings a service supports
- Declares trusted client identities
Correct answer: Declares derived types that the serializer should recognize for polymorphic serialization
[KnownType] tells the DataContractSerializer about derived types of a base type so polymorphic objects can be properly serialized and deserialized.
Question 3: Which WCF binding supports WS-Security, reliable messaging, and transactions over HTTP?
- BasicHttpBinding
- WSHttpBinding (Correct answer)
- NetTcpBinding
- WebHttpBinding
Correct answer: WSHttpBinding
WSHttpBinding implements WS-* standards including WS-Security, WS-ReliableMessaging, and WS-AtomicTransaction over HTTP.
Question 4: Which WCF binding is used to create REST/JSON endpoints instead of SOAP endpoints?
- BasicHttpBinding
- WSHttpBinding
- WebHttpBinding (Correct answer)
- NetHttpBinding
Correct answer: WebHttpBinding
WebHttpBinding enables WCF services to expose REST-style endpoints responding to HTTP verbs (GET, POST, etc.) with JSON or XML.
Question 5: What does setting InstanceContextMode to PerCall mean in WCF service behavior?
- One service instance is shared across all clients
- A new service instance is created for each client session
- A new service instance is created for each incoming operation call (Correct answer)
- The instance count is determined by the binding
Correct answer: A new service instance is created for each incoming operation call
PerCall creates a new service instance for every operation call, disposing it after the call completes, which is stateless and thread-safe by default.
Question 6: Which WCF instancing mode maintains a single shared service instance for all clients and calls?
- PerCall
- PerSession
- Single (Correct answer)
- Pooled
Correct answer: Single
Single instancing mode creates exactly one service instance shared across all clients and all calls, requiring careful thread-safety management.
Question 7: What is the role of a WCF behavior configured with [ServiceBehavior] or IServiceBehavior?
- Defines the message format exchanged between client and service
- Modifies or extends the runtime behavior of the service host or endpoint (Correct answer)
- Specifies the transport protocol for a service endpoint
- Declares which operations are accessible without authentication
Correct answer: Modifies or extends the runtime behavior of the service host or endpoint
WCF behaviors allow you to modify runtime execution characteristics such as throttling, instancing, error handling, and transaction flow without changing the service contract.
Which attribute marks a class as serializable for transfer in WCF messages?