Passing parameters by reference

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan

    Passing parameters by reference

    I posted the following on the remoting board, but it doesn't look like
    there is a lot of traffic there. Maybe someone has an idea of what I
    should try here. That is if everyone's full attention on the C# vs. C
    battle.

    I have set up a little app to work out how I am going to decouple the
    parts of my larger app using remoting. I am trying to pass an object
    by reference to an SAO. I first got the security error that was added
    for 1.1. So, I am using the extended ctor for HttpChannel. I now,
    however, get a new error:

    System.Argument NullException: No message was deserialized prior to
    calling the DispatchChannel Sink

    I am trying to set this up in the code as opposed to a config file for
    other reasons.

    Samples:

    //Shared Assembly
    [Serializable]
    public class PassedParam1 : object, IDo
    {
    public PassedParam1()
    {
    Console.WriteLi ne("PassedParam ­1.ctor");
    }


    public void Do(string Message)
    {
    Console.WriteLi ne("PassedParam ­1: " + Message);
    }



    }


    public class PassedParam2 : MarshalByRefObj ect, IDo
    {
    public PassedParam2()
    {
    Console.WriteLi ne("PassedParam ­2.ctor");
    }

    public void Do(string Message)
    {
    Console.WriteLi ne("PassedParam ­2: " + Message);
    }



    }


    public interface IDo
    {
    void Do(string Message);


    }


    public class Worker : MarshalByRefObj ect
    {
    public Worker()
    {
    Console.WriteLi ne("Worker.ctor ­");
    }

    public void Do(IDo PassedObj)
    {
    PassedObj.Do("S erver Message");
    }



    }


    //Server - Configuration copied from thinktecture.co m
    BinaryServerFor matterSinkProvi ­der serverProv = new
    BinaryServerFor matterSinkProvi ­der();
    serverProv.Type FilterLevel =
    System.Runtime. Serialization.F ­ormatters.Type FilterLevel.Ful l­;

    BinaryClientFor matterSinkProvi ­der clientProv = new
    BinaryClientFor matterSinkProvi ­der();


    IDictionary props = new Hashtable();
    props["port"] = 1234;


    HttpChannel chan =
    new HttpChannel(pro ps, clientProv, serverProv);
    ChannelServices .RegisterChanne ­l( chan );


    RemotingConfigu ration.Register ­WellKnownServi ceType(
    typeof(Worker),
    "Worker",
    WellKnownObject Mode.SingleCall ­);


    //Client
    IDo p1 = new PassedParam1();
    IDo p2 = new PassedParam2();


    ChannelServices .RegisterChanne ­l(new HttpChannel(0)) ;
    Worker w = (Worker)
    RemotingService s.Connect(
    typeof(Worker),
    @"http://localhost:1234/worker");
    w.Do(p1);
    w.Do(p2);


    If I use the standard channel ctor, the first one (ByVal) works fine.
    If I use the detailed ctor as in the code above I get that Null Arg
    error.


    Could someone please point out what I have missed.


    TIA,
    Dan

  • Cordell Lawrence

    #2
    Re: Passing parameters by reference

    Did some remoting code before, I found that I got some exceptions when I
    left out the "name" property of the channel

    .........
    BinaryServerFor matterSinkProvi der serverSinkProvi der = new
    BinaryServerFor matterSinkProvi der();
    serverSinkProvi der.TypeFilterL evel = TypeFilterLevel .Full;

    IDictionary props = new Hashtable();
    props["port"] = 8090;
    props["name"] = string.Empty; // ignore channel names, necessary to prevent
    exceptions

    channel = new TcpChannel(prop s, null, serverSinkProvi der);

    // Register the channel with the remoting framwork
    ChannelServices .RegisterChanne l(channel);
    ..........


    Hope this helps
    Cordell Lawrence
    Teleios Systems Ltd.

    "Dan" <danielshanyfel t@yahoo.com> wrote in message
    news:1113242650 .407379.167250@ o13g2000cwo.goo glegroups.com.. .
    I posted the following on the remoting board, but it doesn't look like
    there is a lot of traffic there. Maybe someone has an idea of what I
    should try here. That is if everyone's full attention on the C# vs. C
    battle.

    I have set up a little app to work out how I am going to decouple the
    parts of my larger app using remoting. I am trying to pass an object
    by reference to an SAO. I first got the security error that was added
    for 1.1. So, I am using the extended ctor for HttpChannel. I now,
    however, get a new error:

    System.Argument NullException: No message was deserialized prior to
    calling the DispatchChannel Sink

    I am trying to set this up in the code as opposed to a config file for
    other reasons.

    Samples:

    //Shared Assembly
    [Serializable]
    public class PassedParam1 : object, IDo
    {
    public PassedParam1()
    {
    Console.WriteLi ne("PassedParam ­1.ctor");
    }


    public void Do(string Message)
    {
    Console.WriteLi ne("PassedParam ­1: " + Message);
    }



    }


    public class PassedParam2 : MarshalByRefObj ect, IDo
    {
    public PassedParam2()
    {
    Console.WriteLi ne("PassedParam ­2.ctor");
    }

    public void Do(string Message)
    {
    Console.WriteLi ne("PassedParam ­2: " + Message);
    }



    }


    public interface IDo
    {
    void Do(string Message);


    }


    public class Worker : MarshalByRefObj ect
    {
    public Worker()
    {
    Console.WriteLi ne("Worker.ctor ­");
    }

    public void Do(IDo PassedObj)
    {
    PassedObj.Do("S erver Message");
    }



    }


    //Server - Configuration copied from thinktecture.co m
    BinaryServerFor matterSinkProvi ­der serverProv = new
    BinaryServerFor matterSinkProvi ­der();
    serverProv.Type FilterLevel =
    System.Runtime. Serialization.F ­ormatters.Type FilterLevel.Ful l­;

    BinaryClientFor matterSinkProvi ­der clientProv = new
    BinaryClientFor matterSinkProvi ­der();


    IDictionary props = new Hashtable();
    props["port"] = 1234;


    HttpChannel chan =
    new HttpChannel(pro ps, clientProv, serverProv);
    ChannelServices .RegisterChanne ­l( chan );


    RemotingConfigu ration.Register ­WellKnownServi ceType(
    typeof(Worker),
    "Worker",
    WellKnownObject Mode.SingleCall ­);


    //Client
    IDo p1 = new PassedParam1();
    IDo p2 = new PassedParam2();


    ChannelServices .RegisterChanne ­l(new HttpChannel(0)) ;
    Worker w = (Worker)
    RemotingService s.Connect(
    typeof(Worker),
    @"http://localhost:1234/worker");
    w.Do(p1);
    w.Do(p2);


    If I use the standard channel ctor, the first one (ByVal) works fine.
    If I use the detailed ctor as in the code above I get that Null Arg
    error.


    Could someone please point out what I have missed.


    TIA,
    Dan


    Comment

    Working...