简体   繁体   中英

Computing on Remote system using C# .NET

I am beginning to create a small cloud platform for learning and expanding to real usage later. I am using C# with WCF. My idea is to have a server and the executor systems. Server will have the jobs that the user submitted to it. Executor systems ask the server for the jobs and execute the jobs and update the result to the server. The job is a C# class object that has method execute() which will be invoked by the executor.

My problem is that how to handover the object along with its methods (behavior) to the Executor so that Executor executes it. With serializing the object, only data will be sent. I am wondering how the Cloud frameworks like Utilify are able to achieve. I am open to any C# technology to execute the job on remote systems, though I prefer WCF.

If you really want to do this you will have to somehow transmit the binary representation of the assembly that your job is defined in to the Executor and then load it into an AppDomain to run your code.

var tempDomain = AppDomain.CreateDomain(someDomain);
tempDomain.Load(myTransmittedAssemblyBytes);

Be aware that you will create a whole world of security vulnerabilities! Make sure you trust any code you are loading.

Alternatively why not have your Executors advertise the types of job they can handle and only send them data they know what to do with.

I would not recommend the binary serialization method. I have tried such a system with sending the binary executable code to worker servers. It was either not possible to do or largely not practical - ( imagine if you have a lot of code to execute. is it practical to send all that code over a network every time you want to execute it? Why not store the code locally and just send variables over the network ).

From memory: I think the problem was with de-serializing/de-coding the assembly bytes into a class which you could call .execute() on. In theory you can cast it into a parent class called MyAction and call .execute() on it, but in practice this did not work.

I agree with the alternate method Bartlett suggested. The 'worker servers' should store a version of a ActionsICanProcess.dll which when queried, can tell the 'job distribution server' which commands it can process. To update a 'worker server' with new job definitions you simply transfer the new 'ActionsICanProcess.dll' to each of the 'worker servers'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM