You are creating an application that consumes a Windows Communication Foundation (WCF) service.
The service implements the IService contract. The client application contains the CallbackHandler class, which implements IServiceCallback.
You need to ensure that a client proxy is created that can communicate with the service over a duplex channel.
Which code segment should you use?
A.
var handler = new CallbackHandler();
var clientFactory = new DuplexChannelFactory<IService>(new WSHttpContextBinding());
var client = clientFactory.CreateChannel(new InstanceContext(handler), new EndpointAddress(“…”));
B.
var handler = new CallbackHandler();
var clientFactory = new DuplexChannelFactory<IService>(typeof(CallbackHandler), new WSDualHttpBinding());
var client = clientFactory.CreateChannel(new InstanceContext(handler), new EndpointAddress(“…”));
C.
var handler = new CallbackHandler();
var clientFactory = new DuplexChannelFactory<IService>(new WSHttpBinding());
var client = clientFactory.CreateChannel(new InstanceContext(handler), new EndpointAddress (“…”));
D.
var handler = new CallbackHandler();
var clientFactory = new DuplexChannelFactory<IService>(typeof(CallbackHandler), new WSDualHttpBinding());
var client = clientFactory.CreateChannel(new EndpointAddress(“…”));
Explanation:
DuplexChannelFactory<TChannel> Class
(http://msdn.microsoft.com/en-us/library/ms576164(v=vs.90).aspx)
How do you know it’s not B?
why is the “handler” object created if it’s never used?
Why B is not correct answer?
It can’t be B because CreateChannel does not take InstanceContext as a parameter. So that only leaves D as the correct answer. See also: http://msdn.microsoft.com/en-us/library/ms576132.aspx
Have to correct myself. The CreateChannel of DuplexChannelFactory has an overload
CreateChannel(InstanceContext, EndpointAddress) as described on http://msdn.microsoft.com/en-us/library/ms576164.aspx Then it would indeed make sense to choose B as the correct answer.
Besides there is no CreateChannel of DuplexChannelFactory that takes just EndPointAddress argument, but there is one in the base class ChannelFactory.
The question says “a client proxy is created that can communicate with the service over a duplex channel..”.
CreateChannel(InstanceContext, EndpointAddress) :Creates a duplex channel between a service and a callback instance on the client.
The correct answer is B.
Just verifying that the correct answer should indeed be B.
A