WCF Question when using ChannelFactory as part of a generic routine....
- From: "Kevin S. Goff" <kgoff@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 23 May 2008 01:32:21 -0400
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
.
- Follow-Ups:
- Prev by Date: Re: How to Edit my Derived Panel in Visual Designer
- Next by Date: Re: WCF Question when using ChannelFactory as part of a generic routine.... (never mind, I'm an idiot)
- Previous by thread: WCF & WF
- Next by thread: Re: WCF Question when using ChannelFactory as part of a generic routine.... (never mind, I'm an idiot)
- Index(es):
Relevant Pages
|