CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: .Net Remoting Question From Beginner

  1. #1
    Join Date
    Feb 2016
    Posts
    4

    .Net Remoting Question From Beginner

    I've recently started with .Net remoting and I have managed to get working with some simple tutorials such as building a library dll that works as a calculator which the client can access and use(https://www.youtube.com/watch?v=Ve4AQnZ-_H0).

    What I'm looking for to understand is how I could access current information that is held on the server. For example if I have this simple part running on the server:

    Code:
    int x = 0;
    
    while (!Console.KeyAvailable)
    {
    x++;
    System.Threading.Thread.Sleep(1000);
    Console.WriteLine(x);
    }


    What I found so far is that the dll built is only returning a static result, such as with the calculator. I'd want to be able to tell how much x is on the server at any given time, through the client.


    I don't know if I'm being clear enough but I'll try to explain better if it's needed.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,469

    Re: .Net Remoting Question From Beginner

    Is there any particular reason you are using .net remoting? I ask because there are other, newer technologies that offer more.

  3. #3
    Join Date
    Feb 2016
    Posts
    4

    Re: .Net Remoting Question From Beginner

    For this project I am stuck using remoting, which I know isn't optimal but I can not use another technology.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,469

    Re: .Net Remoting Question From Beginner

    In the 20 or so years that I've been in business, I only encountered one project where a part of it used .Net Remoting, so I'm certainly no expert.

    What I recall from that experience is that the client and the server must be passing the 'exact' code; otherwise, the remoting doesn't work and fails with some error that doesn't tell that you have a mismatch.

    With your sample code, hopefully the code the code you posted is an illustration only, because that code won't work on the server (because the while loop would prevent a server method request call from ever returning).

    So probably the only advice I could offer is to make sure that the server calls work and return the data before you get to the .Net remoting part. It might also be helpful to bing or google for ".Net Remoting Tutorials" and work through some of the articles first.

  5. #5
    Join Date
    Feb 2016
    Posts
    4

    Re: .Net Remoting Question From Beginner

    What I'm looking to get to the client is a string of information kept and updated on the server. For example for the above example I'd like if the client can somehow know the state of x. For example if it could call a get method, maybe?

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,469

    Re: .Net Remoting Question From Beginner

    Quote Originally Posted by Benji- View Post
    What I'm looking to get to the client is a string of information kept and updated on the server. For example for the above example I'd like if the client can somehow know the state of x. For example if it could call a get method, maybe?
    The point of any server is to set or get data, so what you are looking for is completely doable. Look at some online tutorials - they will show you examples of getting and setting data.

  7. #7
    Join Date
    Feb 2016
    Posts
    4

    Re: .Net Remoting Question From Beginner

    I have been doing that but they all seem to provide a way to do it with static data, like in the example I linked in the first post.

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,469

    Re: .Net Remoting Question From Beginner

    Quote Originally Posted by Benji- View Post
    I have been doing that but they all seem to provide a way to do it with static data, like in the example I linked in the first post.
    Yes, the Proxy class in the youtube video you linked to is coded to return static data. But you have to understand that when the code executes, it runs in the context of the server. So that means you can populate the proxy class with any data you want.

    Consider the following two classes...

    Code:
    // Proxy object that gets remoted
    [Serializable]
    public class Proxy : MarshalByRefObject 
    {
       public string Get()
       {
           var myOtherClass = new MyOtherClass();
           return myOtherClass.GetTheData();
        }
    }
    
    // Other internal class that helps you get data 
    internal class MyOtherClass
    {
       public string GetTheData()
       {
           return "read the data out of somewhere like a database and return it";  // In a real program, this data wouldn't be hard coded
       }
    }
    The first class is the .Net remoted class. The second class helps you retrieve and return data to the proxy class (so that it arrives remoted on the client).

    For clarity, I have the second class code to return static data, but you can certainly replace the hardcoded string inside the GetTheData method with a call to any code that can be accessed from the remoting server (remember when GetTheData is called it is called when in the server context). Try this out by replacing the hard coded string with reading a setting from a config file.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)