Results 1 to 6 of 6

Thread: Remoting and Reflection in C#

  1. #1
    Join Date
    Jun 2009
    Posts
    3,620

    Remoting and Reflection in C#

    By "reflection", is it possible to send the method name and parameters for execution through InvokeMember (...)

    In a run on the local station, no problem, this works well, but when I work with remoting, I do not know how to pass arguments to InvokeMember. Either type is seen as a proxy and I can not do much, either type is necessarily bad (since the interface implements none)

    After searching, I came across blogs.msdn.com/manishg/archive/2004/09/09/227400.aspx, but this does not help me ...

    Can anyone help me?

    Here is more information on the context (if it can help understanding):

    IRemoteOperation.cs
    Code:
    namespace RemotingInterfaces
    {
        public interface IRemoteOperation
        {
            bool Action(type1 param1, type2 param2, ...);
        }
    }
    RemoteOperations.cs
    Code:
    namespace RemotingInterfaces
    {
        public class RemoteOperation : MarshalByRefObject, RemotingInterfaces.IRemoteOperation
        {
            bool Action(type1 param1, type2 param2, ...)
            {
                // Action is executed here
            }
        }
    }
    This works very well sacrificing myself and the action on the pc wanted:
    Code:
    RemotingInterfaces.IRemoteOperation op;
    string pcName = "PC-DE-TEST";
    int port = 12345;
    op = (RemotingInterfaces.IRemoteOperation)Activator.GetObject(
        typeof(RemotingInterfaces.IRemoteOperation),
        "tcp://" + pcName + ":"+port.ToString()+"/RemoteOperation");
    	
    bool b = op.Action(Param1, Param2, ...)
    For economy and code reuse, please send all actions to a more general function:
    Code:
    bool GeneralAction( string action, object [] params)
    This will allow me to do the same operation verification for all actions.

    For local delivery, I have no problem
    Code:
    private bool LocalExecute(string action, object[] myParams)
    {
        Type type1 = typeof(RemoteOperation);
        object obj = Activator.CreateInstance(type1);
        bool res = (bool)type1.InvokeMember(action, System.Reflection.BindingFlags.InvokeMethod, null, obj, myParams);
    }
    But, to run on the client, I can not take the type of op and therefore able to pass through the interface:
    Code:
    private bool RemoteExecute(string action, object[] myParams, string pcName, DateTime expirationDate)
    {
        Type myType = typeof(IRemoteOperation);
        string url = "tcp://" + pcName + ":"+port.ToString()+"/RemoteOperation";
        op = (IRemoteOperation)Activator.GetObject(myType,url);
        //What follows is false!
        Type type2 = typeof(IRemoteOperation);
        
        bool res2 = (bool)type2.InvokeMember(action, System.Reflection.BindingFlags.InvokeMethod,null, op, myParams);
    }
    How?

  2. #2
    Join Date
    Nov 2008
    Posts
    1,192

    Re: Remoting and Reflection in C#

    Your problem is quiet confusing for me. Do you want to say that you are trying to invoke a member of the interface with the reflection on the interface? Can you provide some more information regarding your problem?

  3. #3
    Join Date
    Jun 2009
    Posts
    3,620

    Re: Remoting and Reflection in C#

    That's what I try to do, but I do not see how. Can you make a InvokeMember an interface member?

    Code:
    Type myType = typeof(IRemoteOperation);//type1.GetInterface("RemotingInterfaces.IRemoteOperation");
     
    string url = "tcp://" + pcName + ":"+port.ToString()+"/RemoteOperation";
    IRemoteOperation theRemoteOperation = null;
    theRemoteOperation = (IRemoteOperation)Activator.GetObject(myType,url);
    Code:
    object objro01 = Activator.CreateInstance(myType);
    Creates an exception:
    "Unable to create an interface"
    Code:
    object objro02 = Activator.CreateInstance(theRemoteOperation.GetType());
    creates an exception:
    "Unable to create an abstract method"
    Do you have any idea?

  4. #4
    Join Date
    Nov 2008
    Posts
    1,192

    Re: Remoting and Reflection in C#

    If it is to instantiate objects, you can not with just one interface (a method still it should be feasible). So if you want to create an instance whose type is on the server, I think that you must have applications pending at the server which will have access to classes.

    And although the remoting is used to expose members of the client server because a function that instantiates a machine and returns and the client calls.

  5. #5
    Join Date
    Jun 2009
    Posts
    3,620

    Re: Remoting and Reflection in C#

    But I normally have access to member server

    For example:
    Code:
    RemotingInterfaces.IRemoteOperation op;
    string pcName = "PC-DE-TEST"; 
    int port = 12345;
    op = (RemotingInterfaces.IRemoteOperation)Activator.GetObject(
        typeof(RemotingInterfaces.IRemoteOperation),
        "tcp://" + pcName + ":"+port.ToString()+"/RemoteOperation");
    	
    bool b = op.Action(Param1, Param2, ...)
    I just want to make a
    Code:
    bool b = (bool)TypeX.InvokeMember("op."+action, myParams);
    instead of:
    Code:
    bool b = op.Action(Param1, Param2, ...)
    Do I really need to ask for an instance on a server for that?

    The problem is that:
    Code:
    bool b = (bool)theRemoteOperation.GetType().InvokeMember(action, System.Reflection.BindingFlags.InvokeMethod, null, theRemoteOperation, myParams);
    gives:
    Method 'System.MarshalByRefObject.PopUp' not found.
    where action = "PopUp" exists in the classroom and in the interface.

    Anyway, the server can reply that the following types:
    - IRemoteOperation
    - RemoteOperation
    and the client add:
    - System.MarshalByRefObject

    Ultimately, I want to fix it even though hard, but it will not change whether the server meet me "IRemoteOperation" or that I fixed ...

  6. #6
    Join Date
    Nov 2008
    Posts
    1,192

    Re: Remoting and Reflection in C#

    I'm not really expert in remoting, but you had not seen that particular response I tried my luck. Again I understand your code too and what you want to do. But the principle of remoting is a common interface on each side. This interface is implemented on each side by classes that can be different the server starts listening and exposes a class implementing the interface when a client connects it instantiates an element of class server side and the client sees this forum

    Then he can call members of the interface and the server is responding and to access client side members are cast the instance returned by the server interface, so there is nothing to instantiate ..

Similar Threads

  1. WSUS 3.0 API Remoting Web Service is not working
    By prakashseth in forum Server Update Service
    Replies: 1
    Last Post: 19-12-2012, 01:28 PM
  2. How to use Reflection in Java
    By The$Hulk in forum Guides & Tutorials
    Replies: 4
    Last Post: 12-01-2011, 01:18 PM
  3. Upgrade to CF9 breaks Flex to CF remoting
    By Nilakshi in forum Software Development
    Replies: 5
    Last Post: 10-07-2010, 04:00 AM
  4. .Net Remoting Vs Web Services
    By Jagdish Gada in forum Software Development
    Replies: 5
    Last Post: 22-01-2010, 02:06 PM
  5. Download Wrq Reflection Suite
    By TAARIQ in forum Operating Systems
    Replies: 3
    Last Post: 04-06-2009, 09:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,141,318.27175 seconds with 17 queries