从 WCF 服务返回接口 [英] Returning an interface from a WCF service
问题描述
我有一些 .NET 远程处理代码,其中在某些服务器端类中实现的工厂方法返回到具体对象的接口,也在同一台服务器上执行..NET 远程处理会自动创建代理并允许我将接口传递给客户端,然后客户端可以直接调用它们.
I have some .NET remoting code where a factory method, implemented in some server side class, returns interfaces to concrete objects, also executing on the very same server. .NET remoting automagically creates proxies and allows me to pass the interfaces across to the client, which can then call them directly.
示例接口:
public interface IFactory
{
IFoo GetFoo();
}
public interface IFoo
{
void DoSomething();
}
示例客户端代码:
...
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 ();
...
这一切都很好.但是,现在我正在尝试将我的代码迁移到 WCF.我想知道是否有一种方法可以传递接口并让 WCF 在客户端上动态生成代理,就像原始的 .NET 远程处理一样.
This all works great. However, now I am trying to migrate my code to WCF. I wonder if there is a means to pass around interfaces and having WCF generate the proxies on the fly on the client, as does the original .NET remoting.
而且我不想返回类实例,因为我不想公开真正的类.序列化完整实例并在服务器和客户端之间来回发送也不是一种选择.我真的只是希望客户端通过接口指针/代理与服务器对象交谈.
And I don't want to return class instances, since I don't want to expose real classes. And serializing the full instance and sending it back and forth between the server and the client is not an option either. I really just want the client to talk to the server object through an interface pointer/proxy.
有什么想法吗?
推荐答案
这篇关于从 WCF 服务返回接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!