Hack Forums
[C#] C# Remote Method Invoking - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] C# Remote Method Invoking (/showthread.php?tid=2422674)



C# Remote Method Invoking - mysnphit - Apr 21, 2012

Hello HF!

This is my preview of my very basic and simple RemoteMethod class. It is currently able to invoke public static methods in public classes on the client (only works if the return value and the parameters are serializable), and return the return value to the server (via a encrypted tcp connection).

Thanks to DragonHunter for the Sync concept!

Video:
Spoiler (Click to View)

Sorry for my English im Dutch


* - BaussHacker - Apr 21, 2012

Wouldn't this be much easier?
https://hackforums.net/showthread.php?tid=2338582

Code
public class WebLibrary
    {
  private Dictionary<string, byte[]> libCollection;
  private string webUrl;

  public WebLibrary(Uri webUri)
  {
    webUrl = webUri.ToString();
    libCollection = new Dictionary<string, byte[]>();
  }
  public WebLibrary(string webUrl)
  {
    this.webUrl = webUrl;
    libCollection = new Dictionary<string, byte[]>();
  }

  public void Add(string LibraryName)
  {
    WebClient wc = new WebClient();
    byte[] data = wc.DownloadData(webUrl.EndsWith("/") ? webUrl + LibraryName + ".dll" : webUrl + "/" + LibraryName + ".dll");
    libCollection.Add(LibraryName, data);
  }

  public void InvokeMethod(string LibraryName, string Class, string MethodName, object[] Parameters = null)
  {
    Assembly.Load(libCollection[LibraryName])
  .GetType(LibraryName + "." + Class).GetMethod(MethodName).Invoke(null, Parameters);
  }
    }



* - mysnphit - Apr 21, 2012

(Apr 21, 2012 04:17 AM)Ԍray Wrote:  Wouldn't this be much easier?
https://hackforums.net/showthread.php?tid=2338582

Code
public class WebLibrary
    {
  private Dictionary<string, byte[]> libCollection;
  private string webUrl;

  public WebLibrary(Uri webUri)
  {
    webUrl = webUri.ToString();
    libCollection = new Dictionary<string, byte[]>();
  }
  public WebLibrary(string webUrl)
  {
    this.webUrl = webUrl;
    libCollection = new Dictionary<string, byte[]>();
  }

  public void Add(string LibraryName)
  {
    WebClient wc = new WebClient();
    byte[] data = wc.DownloadData(webUrl.EndsWith("/") ? webUrl + LibraryName + ".dll" : webUrl + "/" + LibraryName + ".dll");
    libCollection.Add(LibraryName, data);
  }

  public void InvokeMethod(string LibraryName, string Class, string MethodName, object[] Parameters = null)
  {
    Assembly.Load(libCollection[LibraryName])
  .GetType(LibraryName + "." + Class).GetMethod(MethodName).Invoke(null, Parameters);
  }
    }

RemoteMethod is more dynamic, because the server can call all the static methods on the client side just by running the class, without downloading a dll or something, just with a encrypted tcp connection between the two pc's.


* - BaussHacker - Apr 21, 2012

Oh wait, I misunderstoof OP, nevermind, just ignore my post.