开发者

WCF serialization of Method Bodies

I'm writing some kind of Computing farm with central server giving tasks and nodes that compute them.

I wanted to write it in such way, that nodes don't know what exactly they are computing. They get (from server) an object that implements IComputable iterface, has one method, .compute() that returns IResult type object and send it to the server.

Server is responsible for preparing these object and serving them through .getWork() method on wcf service, and gets the results with .submitResult(IResult result) method.

Problem is, that worker nodes need to know not only the interface, but full object implementation. I know that Java c开发者_如何学Pythonan serialize method (probably to bytecode) through RMI. Is it possible with c# ?


What you will have to do is put the type which implements the method you are describing into a separate assembly. You can then send the assembly as a byte array to your server, where it will load the assembly, insptect it for types that fit your interface, and then load them. This is the basic pattern for plug-ins using .Net.

Some care has to be taken though. If you are accepting code from arbitrary sources, you will have to lockdown what these loaded assemblies can do (and it is good practice to do even if you trust the source).

A good classic example for how to do this is the Terrarium project. It is a case study that Microsoft produced that involved the viral spreading of arbitrary assemblies in a secure fashion.


You can do

System.Expression.LambdaExpression<Func<result>> lambda = MyFunction;

and then you can serialize expression to string and deserialize on the server

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜