How can I pass my client-side object to my server object in .net remoting?
This is how I'm doing my test. On my class library:
public interface IServer
{
bool SubmitMessage( ISampleClass sample );
}
[Serializable]
public Server : MarshalByRefObject , IServer
{
Public Server()
{
}
public bool SubmitMessage( ISampleClass sample )
{
return true;
}
}
public interface ISampleClass
{
string GetName();
}
[Serializable]
public class SampleClass : MarshalByRefObject , ISampleClass
{
public SampleClass()
{
}
public string GetName()
{
return "test";
}
}
On my Server Application:
IChannel channel = new TcpChannel(9988);
ChannelServices.RegisterChannel(channel,false);
RemotingConfiguration.RegisteredWellKnownServiceType( typeof(Testing.Server) ,"testremote",WellKnownObjectMode.Singleton);
RemotingConfiguration.RegisterActivatedServiceType(typeof(Testing.SampleClass));
RemotingConfiguration.ApplicationName = "TestRemote";
On my Client Application:
Type type = typeof(Testing.Server);
Testing.IServer server = (Testing.IServer)Activator.GetOject(type,"tcp://localhost:9988/testremote");
RemotingConfiguration.RegisteredActivatedClientType(typeof(Testing.SampleClass), "tcp://localhost:9988/TestRemote");
Testing.SampleClass test = new Testing.SampleClass(); // proxy class
server.SubmitMessage(test); // Error here
The error I encoutered was: Because of security restrictions, the type System.Runtime.Remoting.ObjRef cannot be accessed. Inner Exception: Request Failed.
Please tell me what I'm doing wrong. Thanks!