WCF

WCF Examples

WCF

WCF Projects

WCF Project

adplus-dvertising
The DuplexChannelFactory<T,C> class
Previous Home Next

DuplexChannelFactory<T> is a base class, ChannelFactory<T>, except its constructors expect either a callback instance or a callback context. The use of object for the callback instance and the lack of type safety. Similar to fixing up the DuplexClientBase<T> class.

public class DuplexChannelFactory<T,C> : DuplexChannelFactory<T> 
where T : class
{
static DuplexChannelFactory( )
{
DuplexClientBase<T,C>.VerifyCallback( );
}
public static T CreateChannel(C callback,string EPName)
{
return DuplexChannelFactory<T>.CreateChannel(callback,EPName);
}
public static T CreateChannel(InstanceContext<C> context,string EPName)
{
return DuplexChannelFactory<T>.CreateChannel(context.Context,EPName);
}
public static T CreateChannel(C callback,Binding binding,
EndpointAddress endpointAddress)
{
return DuplexChannelFactory<T>.CreateChannel(callback,binding,
  endpointAddress);
}
public static T CreateChannel(InstanceContext<C> context,Binding binding,
EndpointAddress endpointAddress)
{
return DuplexChannelFactory<T>.CreateChannel(context,binding,
endpointAddress);
}
public DuplexChannelFactory(C callback) : base(callback)
{}
public DuplexChannelFactory(C callback,string EPName):
 base(callback,EPName)
{}
public DuplexChannelFactory(InstanceContext<C> context,string EPName) :
 base(context.Context,EPName)
{}
//More constructors
}

Adding duplex support to InProcFactory:

public static class InProcFactory
{
public static I CreateInstance<S,I,C>(C callback) where I : class
  where S : class,I
{
InstanceContext<C> context = new InstanceContext<C>(callback);
return CreateInstance<S,I,C>(context);
}
public static I CreateInstance<S,I,C>(InstanceContext<C> context)
  where I : class
  where S : class,I
{
HostRecord hostRecord = GetHostRecord<S,I>( );
return  DuplexChannelFactory<I,C>.CreateChannel(
  context,NamedPipeBinding,new EndpointAddress(hostRecord.Address));
}
//More members
}
//Sample client
IMyContractCallback callback = new MyClient( );
IMyContract proxy = InProcFactory.CreateInstance
  <MyService,IMyContract,IMyContractCallback>(callback);
proxy.DoSomething( );
InProcFactory.CloseProxy(proxy);
Previous Home Next