473,320 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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<ToChannelFactory = 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(IMyCo ntract));
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
Jun 27 '08 #1
3 8285
too much pizza tonight, must have killed my brain cells...figured it out...
public T GetGeneralFactoryChannel<T>()
{

Binding myBinding = new WSHttpBinding();
ChannelFactory<ToChannelFactory = 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 = this.GetRemoteFactoryChannel<IUser>();
MyContract.CallSomeMethod();
Thanks to the following blog!
http://aabs.wordpress.com/2007/12/31...attern-in-net/
Kevin
Jun 27 '08 #2
Marc Gravell wrote:
Another option:
http://groups.google.com/group/micro...2663dfa6be9bf4

Marc


Thanks, Marc! I actually use typed datasets, so that will come in
handy. Thanks!

Kevin
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I...
6
by: Mårten Herberthson | last post by:
Introduction: As we all know, values of any class may be assigned to a reference of a superclass. This is simple polymorphism. So if you have a class A and a class B that inherits from A you can...
4
by: David Douglass | last post by:
I'm confused about the program below. Based on my reading of the C# spec, I don't think it should compile, but it does when using Beta 1. Could somebody please explain the function selection...
2
by: =?Utf-8?B?c21pdGhrbDQy?= | last post by:
I'm just now beginning to experiment with WCF, and I've run into an odd hiccup right at the beginning. I presume it's just something I'm doing wrong, but I can't figure it out. I've created a...
3
by: Marco Shaw | last post by:
I've got some C# code to create a custom PowerShell cmdlet with these statements: .... using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; .... ...
0
by: rote | last post by:
I have a project i created using TableAdapters(Datasets with .xsd) and everything works well on my PC. But when i create a websetup project and deploy it to another server. I keep getting Error...
3
by: Tony Johansson | last post by:
Hello! You can set target Module for AttributeUsage. I just wonder what does it mean with module ? //Tony
13
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
This is a follow-up to my post "Silverlight video doesn't work when file is streamed from handler in ASP.net" at...
0
by: lgwapnitsky | last post by:
I am writing an Outlook add-in that needs to fire when a PST is added/removed. I have successfully fired the event using the AddStore and RemoveStore functions, as well as when I use the "Open ->...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.