Passing parameters by reference

D

Dan

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.ArgumentNullException: No message was deserialized prior to
calling the DispatchChannelSink

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.WriteLine("PassedParam­1.ctor");
}


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



}


public class PassedParam2 : MarshalByRefObject, IDo
{
public PassedParam2()
{
Console.WriteLine("PassedParam­2.ctor");
}

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



}


public interface IDo
{
void Do(string Message);


}


public class Worker : MarshalByRefObject
{
public Worker()
{
Console.WriteLine("Worker.ctor­");
}

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



}


//Server - Configuration copied from thinktecture.com
BinaryServerFormatterSinkProvi­der serverProv = new
BinaryServerFormatterSinkProvi­der();
serverProv.TypeFilterLevel =
System.Runtime.Serialization.F­ormatters.TypeFilterLevel.Full­;

BinaryClientFormatterSinkProvi­der clientProv = new
BinaryClientFormatterSinkProvi­der();


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


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


RemotingConfiguration.Register­WellKnownServiceType(
typeof(Worker),
"Worker",
WellKnownObjectMode.SingleCall­);


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


ChannelServices.RegisterChanne­l(new HttpChannel(0));
Worker w = (Worker)
RemotingServices.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
 
C

Cordell Lawrence

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

.........
BinaryServerFormatterSinkProvider serverSinkProvider = new
BinaryServerFormatterSinkProvider();
serverSinkProvider.TypeFilterLevel = TypeFilterLevel.Full;

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

channel = new TcpChannel(props, null, serverSinkProvider);

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


Hope this helps
Cordell Lawrence
Teleios Systems Ltd.

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.ArgumentNullException: No message was deserialized prior to
calling the DispatchChannelSink

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.WriteLine("PassedParam­1.ctor");
}


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



}


public class PassedParam2 : MarshalByRefObject, IDo
{
public PassedParam2()
{
Console.WriteLine("PassedParam­2.ctor");
}

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



}


public interface IDo
{
void Do(string Message);


}


public class Worker : MarshalByRefObject
{
public Worker()
{
Console.WriteLine("Worker.ctor­");
}

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



}


//Server - Configuration copied from thinktecture.com
BinaryServerFormatterSinkProvi­der serverProv = new
BinaryServerFormatterSinkProvi­der();
serverProv.TypeFilterLevel =
System.Runtime.Serialization.F­ormatters.TypeFilterLevel.Full­;

BinaryClientFormatterSinkProvi­der clientProv = new
BinaryClientFormatterSinkProvi­der();


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


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


RemotingConfiguration.Register­WellKnownServiceType(
typeof(Worker),
"Worker",
WellKnownObjectMode.SingleCall­);


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


ChannelServices.RegisterChanne­l(new HttpChannel(0));
Worker w = (Worker)
RemotingServices.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top