2010-07-07 3 views
1

Comment puis-je transmettre mon objet côté client à mon objet serveur dans .net remoting?Passer l'objet créé par le client sur le serveur .net remoting

Voici comment je fais mon test. Sur ma bibliothèque de classes:

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"; 
    } 
} 

Sur mon serveur d'applications:

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"; 

Sur mon application client:

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 

L'erreur que j'encoutered était: En raison des restrictions de sécurité, Vous ne pouvez pas accéder à System.Runtime.Remoting.ObjRef. Exception interne: la demande a échoué.

S'il vous plaît dites-moi ce que je fais mal. Merci!

Répondre

0

J'ai déjà découvert ce que je fais mal. La classe SampleClass ne doit pas avoir hérité de MarshalByRefObject.

Peut-être cela peut être de référence future à d'autres.

Questions connexes