C# call external function (class other machine)

1.4k views Asked by At

It it possible to call a function on an external class? The external class runs on another machine (say its locations is mymachine.com). have used CreateInstance some time ago but don't think that will do (correct me if I'm wrong). I have been searching for a long time but haven't found a solution yet so I hope one of you can help.

one of the sources i have searched is but no info :( http://www.dreamincode.net/forums/topic/102523-call-an-external-function-on-button-click/

hope u can help.

4

There are 4 answers

0
Steve B On

use a self hosted WCF service, remoting or any networking technology.

There is unfortunately no magic attribute to achieve that.

[Edit] I also would like to add that you me be careful. When you are using some remoting mechanisms (either remoting, WCF, rpc, etc.) you work with "proxies". A proxy is an object that simulate the actual object, but encapsulate the communication. It allow the developer to hide the complexity by having an objects, with properties, methods etc., but the technologies behind (xml messaging for a WCF service for example) must be known by the developer. It can have impacts on network, responsiveness, and also programming model.

0
Matthew Abbott On

This sort of operation is what Web Services / WCF Services / Remoting is built for. WCF is a really nice solution for handling communication across boundaries. Have a look into WCF, google is your friend.

0
Harold Sota On

See these: http://www.aspfree.com/c/a/.NET/Introduction-to-RPC-on-Windows-Part-I/ http://www.csharphelp.com/2007/01/interprocess-communication/

0
code4life On

If the external assembly is on a shared folder on the remote machine, then you can do one of the following:

1) Implement the AppDomain.CurrentDomain.AssemblyResolve event handler to load the external assembly, and make the calls you need to make. Also put a reference to the assembly in your project by the way (copylocal=false). The first call to instance a class or static method in the assembly will invoke the event handler and load the remote external assembly.

2) Load the assembly via reflection using System.Reflection.Assembly.LoadFrom() and provide te remote path. Use reflection to invoke the desired method, etc.