Which code segment should you use?

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?

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)



Leave a Reply 8

Your email address will not be published. Required fields are marked *


ron

ron

How do you know it’s not B?

why is the “handler” object created if it’s never used?

Tom

Tom

Why B is not correct answer?

Igor

Igor

Besides there is no CreateChannel of DuplexChannelFactory that takes just EndPointAddress argument, but there is one in the base class ChannelFactory.

Abhishek

Abhishek

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.

John Galt

John Galt

Just verifying that the correct answer should indeed be B.