In WCF is it possible to pass a delegate to the remote object?

纵饮孤独 提交于 2020-01-06 02:44:07

问题


Is it possible to pass a delegate to a WCF remote object from the client and have the remote object execute the delegate?

I would guess not since a delgate is a function pointer for the client process.

My goal is to have an interface structure that I can "subscribe" to events from a client to the interface. I would pass a delgate from the client to the interface and I want the interface to be able to execute the event.

The idea is to have the ability for the interface to be loaded either the assembly or remotly and have the code work the same.

If I can't pass the delegate how can I implement an event structure?


回答1:


not a "delegate" in C# per se, but in WCF you have duplex bindings to enable call back from the service side to the client side

http://msdn.microsoft.com/en-us/library/system.servicemodel.wsdualhttpbinding.aspx




回答2:


I doubt you could come up with a cohesive way to pass a delegate from a C# client to a Java service implementation and have it properly executed......

WCF is not a strict .NET implementation and thus has to deal with interop issues. It cannot rely on the assumption that both ends of the conversation are in .NET - that's why you shouldn't throw around custom exceptions between server and client either (exceptions are a .NET construct) - you need to use SOAP faults instead (which are interoperable).

So I don't think what you want to do can be done with a delegate - you'll have to come up with another way to achieve your goal.

Marc



来源:https://stackoverflow.com/questions/837274/in-wcf-is-it-possible-to-pass-a-delegate-to-the-remote-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!