Return interface from WCF service

I have some .NET remote code, where the factory method, implemented in a certain class on the server side, returns interfaces to specific objects also running on the same server .. NET remoting automatically creates proxy servers and allows you to transfer interfaces through a client who can then call them directly.

Interface examples:

public interface IFactory { IFoo GetFoo(); } public interface IFoo { void DoSomething(); } 

Example client code:

 ... IFactory factory = (IFactory) System.Activator.GetObject (typeof (IFactory), url); ... IFoo foo = factory.GetFoo (); // the server returns an interface; we get a proxy to it foo.DoSomething (); ... 

It all works great. However, now I am trying to port my code to WCF. I wonder if there is a way to bypass the interfaces and force WCF to generate proxies on the fly on the client, as well as the original remote .NET.

And I do not want to return instances of classes, since I do not want to show real classes. And serializing a full instance and sending it back and forth between the server and the client is also not an option. I just want the client to talk to the server object through a pointer / proxy interface.

Any ideas?

+6
source share
3 answers

Sorry jezell i don't understand.

Yes, I can use ChannelFactory on the client to create a proxy server for IFactory , since this singleton object was "published" by the server through a URI on ServiceHost .

But my IFoo instances on the server are not associated with any ServiceHost ; I just want to get them back by calling my IFactory on the client, and let WCF make a call to the IFactory server, which will provide some IFoo , which will then be redirected back to the client and wrapped in a dynamically generated proxy. I just want to write factory.GetFoo (); on my client ...

At the same time, Brian pointed me to a very interesting document, which I missed from MSDN, which explains how to control the setting of the .NET Remoting interface using sessions and EndPointAddress10 and ... as you wrote, ChannelFactory for receiving proxies on the side customer.

So now I know how to replicate my remote .NET code, but at a relatively high cost. The code complexity associated with WCF is slightly higher than with a simple old .NET remote solution.

+1
source

The ChannelFactory class does just that, dynamically generates proxies at runtime, taking into account the interface.

0
source

All Articles