WCF Question when using ChannelFactory as part of a generic routine....



I may be trying to do something that can't be done (or "shouldn't" be done), but here goes.

I'm trying to construct a generalized method for creating a client-side factory channel using WCF. So that I can pass it any one of dozens of interface contracts, and the method will pump out a proxy.

So essentially, I want to do this...

public T GetGeneralFactoryChannel<T>(T interfaceType)
{

Binding myBinding = new WSHttpBinding();
ChannelFactory<T> oChannelFactory = new ChannelFactory<T>(myBinding);
oChannelFactory.Endpoint.Address = new
EndpointAddress("http://MyServer//testwcf/service.svc";);

T MyProxyChannel = oChannelFactory.CreateChannel();

return MyProxyChannel;
}

And then I can call it like so:

IMyContract MyContract;
MyContract = (IMyContract)GetGeneralFactoryChannel(typeof(IMyContract));
MyContract.CallSomeMethod();

The problem is that I get errors when the code tries to create a channel factory..."The type argument passed to the generic ChannelFactory class must be an interface type".

I tried using MakeGenericType, but that didn't help.

So anyway, has anyone tried to do something similar? (using ChannelFactory inside something generic, so that you could pass any contract interface?)

I was hoping to avoid reflection or Activator.GetObject, but if that's the only way to get this to work...

Feel free to suggest an alternate approach....

Thanks,
Kevin
.



Relevant Pages

  • [RFC PATCH 1/6] Driver Tracing Interface (DTI) Documentation
    ... named 'The Driver Tracing Interface ' after the title of our OLS ... The Driver Tracing Interface introduced here does essentially the same ... DTI is also very useful as a debugging tool for kernel development. ... single DTI channel across multiple 'subsystems' as well as custom ...
    (Linux-Kernel)
  • Re: [PATCH] w35und: fix usb_control_msg() error handling in wb35_probe()
    ... usb 1-3: new high speed USB device using ehci_hcd and address 4 ... wlan0 Interface doesn't support scanning: ... Frequency:2.412 GHz (Channel 1) ... IE: Unknown: 0004686F6D65 ...
    (Linux-Kernel)
  • Re: Recording system for student
    ... Any interface that accepts standard line levels can be used with any ... Another *very* important thing is driver support for devices, ... a 4 channel interface like the M-Audio "Fast Track Pro" ...
    (rec.audio.pro)
  • Re: need clarification on trunking and setting up port-channel
    ...  switchport trunk allowed vlan 2-4094 ... as well double your bandwidth and use a port channel. ... If I understood it correctly, the "Port-channel1" interface will be ...
    (comp.dcom.sys.cisco)
  • Re: www Sony PSP 31 3
    ... How many frequency settings are there per channel on the Maselec ... What is the stereo linking system on the Maselec MLA-2 compressor ... FireWire Interface, ... What is the limiter function in the Prism Sound ADA-8XR called? ...
    (uk.rec.competitions)