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?
Bookmarks