U
Uchiha Jax
Hello everyone,
I am a plenty silly person who is trying to
learn .NET remoting through trial and error (all articles I read are going
over my head at the moment (mostly) so I thought i'd give it a go).
What I want to do is this:
Have a server instance of the program, this server instance will receive
communication from client programs (as demonstrated in the AddMessage()
method of the RemoteObject) and then send data back to them (obviously the
true scale of this isn't really implemented here, this is proof of concept).
Unfortunately whenever I try to assign a delegate to a RemoteObject I get an
error. It used to be security error about Serialization but then I found out
about TypeFilterLevel, having fixed that I now get this error instead.
An unhandled exception of type
'System.Runtime.Serialization.SerializationException' occurred in
mscorlib.dll
Additional information: Cannot find the assembly MyRemoteClient,
Version=1.0.1843.39632, Culture=neutral, PublicKeyToken=null.
As you can probably guess this isn't the most helpful of error messages as
this happens in the MyRemoteClient.exe so I cant understand how it can't
find itself, but i'm sure i'm doing something very stupid and impeach you
all to point out my stupidity to me so that I may learn the error of my
ways.
////////////Here is the client code (this is where I get the exception)
using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Channels.Tcp;
namespace MyRemoteTest
{
class RemoteClient
{
static void Main(string[] args)
{
BinaryServerFormatterSinkProvider serverProv = new
BinaryServerFormatterSinkProvider();
serverProv.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
BinaryClientFormatterSinkProvider clientProv = new
BinaryClientFormatterSinkProvider();
IDictionary props = new Hashtable();
props["port"] = 1000;
TcpChannel channel = new TcpChannel( props, clientProv, null );
ChannelServices.RegisterChannel( channel );
RemoteObj remObj = (RemoteObj) Activator.GetObject( typeof ( RemoteObj ),
"tcp://localhost:1099/RemoteObj" );
remObj.ReplyDel = new ReplyDelegate(WriteMessage); // This is where I get
the exception
string message = "We have connected a user. Whoo!";
remObj.AddMessage( message, 1000 );
while (message.ToLower().StartsWith( "quit" ) == false)
{
Console.WriteLine( "Enter a Message to Add to Server, 'quit' to exit
application" );
message = Console.ReadLine();
remObj.AddMessage( message, 1000 );
}
}
static void WriteMessage(string message)
{
Console.WriteLine(message);
}
}
}
//// Here is ServerCode
using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Channels.Tcp;
namespace MyRemoteTest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class RemoteServer
{
/// <summary>
/// Entry Point into this application
/// </summary>
public static void Main()
{
BinaryServerFormatterSinkProvider serverProv = new
BinaryServerFormatterSinkProvider();
serverProv.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
IDictionary props = new Hashtable();
props["port"] = 1099;
TcpChannel channel = new TcpChannel( props, null, serverProv );
ChannelServices.RegisterChannel( channel );
RemotingConfiguration.RegisterWellKnownServiceType( typeof( RemoteObj ),
"RemoteObj",
WellKnownObjectMode.SingleCall );
Console.WriteLine( "The Topic Server is up and running on port {0}",
1099 );
Console.WriteLine( "Press enter to stop the server..." );
Console.ReadLine();
}
}
}
///// Here is remote obj and delegate definition
using System;
using System.Collections;
using System.Runtime.Remoting;
namespace MyRemoteTest
{
[Serializable]
public class RemoteObj: MarshalByRefObject
{
private ReplyDelegate replyDel;
public ReplyDelegate ReplyDel
{
set{replyDel = value;}
}
public RemoteObj()
{
}
public void AddMessage(string message, int userID)
{
string announce = String.Format("User {0} said: {1}", userID,message);
Console.WriteLine(announce);
replyDel(announce);
}
}
public delegate void ReplyDelegate(string announce);
}
/////////////////////////////////
I am a plenty silly person who is trying to
learn .NET remoting through trial and error (all articles I read are going
over my head at the moment (mostly) so I thought i'd give it a go).
What I want to do is this:
Have a server instance of the program, this server instance will receive
communication from client programs (as demonstrated in the AddMessage()
method of the RemoteObject) and then send data back to them (obviously the
true scale of this isn't really implemented here, this is proof of concept).
Unfortunately whenever I try to assign a delegate to a RemoteObject I get an
error. It used to be security error about Serialization but then I found out
about TypeFilterLevel, having fixed that I now get this error instead.
An unhandled exception of type
'System.Runtime.Serialization.SerializationException' occurred in
mscorlib.dll
Additional information: Cannot find the assembly MyRemoteClient,
Version=1.0.1843.39632, Culture=neutral, PublicKeyToken=null.
As you can probably guess this isn't the most helpful of error messages as
this happens in the MyRemoteClient.exe so I cant understand how it can't
find itself, but i'm sure i'm doing something very stupid and impeach you
all to point out my stupidity to me so that I may learn the error of my
ways.
////////////Here is the client code (this is where I get the exception)
using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Channels.Tcp;
namespace MyRemoteTest
{
class RemoteClient
{
static void Main(string[] args)
{
BinaryServerFormatterSinkProvider serverProv = new
BinaryServerFormatterSinkProvider();
serverProv.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
BinaryClientFormatterSinkProvider clientProv = new
BinaryClientFormatterSinkProvider();
IDictionary props = new Hashtable();
props["port"] = 1000;
TcpChannel channel = new TcpChannel( props, clientProv, null );
ChannelServices.RegisterChannel( channel );
RemoteObj remObj = (RemoteObj) Activator.GetObject( typeof ( RemoteObj ),
"tcp://localhost:1099/RemoteObj" );
remObj.ReplyDel = new ReplyDelegate(WriteMessage); // This is where I get
the exception
string message = "We have connected a user. Whoo!";
remObj.AddMessage( message, 1000 );
while (message.ToLower().StartsWith( "quit" ) == false)
{
Console.WriteLine( "Enter a Message to Add to Server, 'quit' to exit
application" );
message = Console.ReadLine();
remObj.AddMessage( message, 1000 );
}
}
static void WriteMessage(string message)
{
Console.WriteLine(message);
}
}
}
//// Here is ServerCode
using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Channels.Tcp;
namespace MyRemoteTest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class RemoteServer
{
/// <summary>
/// Entry Point into this application
/// </summary>
public static void Main()
{
BinaryServerFormatterSinkProvider serverProv = new
BinaryServerFormatterSinkProvider();
serverProv.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
IDictionary props = new Hashtable();
props["port"] = 1099;
TcpChannel channel = new TcpChannel( props, null, serverProv );
ChannelServices.RegisterChannel( channel );
RemotingConfiguration.RegisterWellKnownServiceType( typeof( RemoteObj ),
"RemoteObj",
WellKnownObjectMode.SingleCall );
Console.WriteLine( "The Topic Server is up and running on port {0}",
1099 );
Console.WriteLine( "Press enter to stop the server..." );
Console.ReadLine();
}
}
}
///// Here is remote obj and delegate definition
using System;
using System.Collections;
using System.Runtime.Remoting;
namespace MyRemoteTest
{
[Serializable]
public class RemoteObj: MarshalByRefObject
{
private ReplyDelegate replyDel;
public ReplyDelegate ReplyDel
{
set{replyDel = value;}
}
public RemoteObj()
{
}
public void AddMessage(string message, int userID)
{
string announce = String.Format("User {0} said: {1}", userID,message);
Console.WriteLine(announce);
replyDel(announce);
}
}
public delegate void ReplyDelegate(string announce);
}
/////////////////////////////////