Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 04-12-2009
Member
 
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?
Reply With Quote
  #2  
Old 04-12-2009
Member
 
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?
Reply With Quote
  #3  
Old 04-12-2009
Member
 
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:
Quote:
"Unable to create an interface"
Code:
object objro02 = Activator.CreateInstance(theRemoteOperation.GetType());
creates an exception:
Quote:
"Unable to create an abstract method"
Do you have any idea?
Reply With Quote
  #4  
Old 04-12-2009
Member
 
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.
Reply With Quote
  #5  
Old 04-12-2009
Member
 
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:
Quote:
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 ...
Reply With Quote
  #6  
Old 04-12-2009
Member
 
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 ..
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 05:45 PM.