Bulldog.NET

Hi

Im new in System.Runtime.Remoting Class. I want to know if its possible to Create an instance on the remote server and call a method remotely without adding a server reference file.

Currently I have :-

ServerCode

Code Snippet

namespace TopicServer

{

///

/// A Bulletin Board Server that buffers messages

///

public class TopicServer : MarshalByRefObject

{

string serverId = Guid.NewGuid().ToString();

public string addMessage(string clientID, string message)

{

messageList_.Add(message);

Console.WriteLine("From ClientID :" + clientID + ", Message Added :" + message);

return "Server Id : " + serverId + " Response";

}

}

public class TheServer

{

public static void Main()

{

int listeningChannel = 1099;

TcpChannel channel = new TcpChannel( listeningChannel );

ChannelServices.RegisterChannel(channel);

RemotingConfiguration.RegisterWellKnownServiceType(typeof(TopicServer),"Topic", WellKnownObjectMode.Singleton);

Console.WriteLine("The Topic Server is up and running on tcp port {0}", listeningChannel);

Console.WriteLine("Press enter to stop the server...");

Console.ReadLine();

}

}

}

Client Code :-

Code Snippet

using TopicServer;

namespace TopicClient

{

/// <summary>

/// The Client to a Distributed Bulletin Board Server

/// </summary>

class TopicClient

{

static void Main(string[] args)

{

try

{

int listeningChannel = Int32.Parse(1000);

TcpChannel channel = new TcpChannel(listeningChannel);

ChannelServices.RegisterChannel(channel);

TopicServer topic = (TopicServer)Activator.GetObject(typeof(TopicServer), "tcp://myserver:1099/Topic");

if (topic == null)

{

Console.WriteLine("Unable to obtain a Reference to the Remote Topic Server component ...");

return;

}

string clientID = Guid.NewGuid().ToString();

string message = "New Client ID: " + clientID + ", Connected From Port " + listeningChannel;

Console.WriteLine(topic.displayMessage(clientID, message));

while (message.ToLower().StartsWith("quit") == false)

{

Console.WriteLine("Enter a Message to Add to Server, 'quit' to exit application");

message = Console.ReadLine();

Console.WriteLine(topic.addMessage(clientID, message));

}

Console.WriteLine("The Messages Are:" + topic.retrieveAllMessages(clientID));

topic.displayMessage(clientID,

"Client " + clientID +

": Connected From Port " + listeningChannel +

", Terminating...");

}

catch (Exception ex)

{

Console.WriteLine(ex.ToString());

Console.ReadLine();

}

}

}

}

Notice in my client code I had to reference the Server namespace using TopicServer; Is it possible to do without referencing to the server class or any other alturnative. I want ServerCode exe file to run on the server machine and the cliect exe to run only on the client machine via LAN connection.




Re: .NET Remoting and Runtime Serialization How can I remote to server using .NET Remoting?

Chris Hawkins

The bottom line is that both the server and the client both need access to the remote object. The best method is probably to compile the TopicServer class into a class library dll and then give the server and client access to that dll.






Re: .NET Remoting and Runtime Serialization How can I remote to server using .NET Remoting?

mahjayar

Like Chris mentioned, At the very least your client needs to know the type and methods available on that type that it can call. So you can compile the signature of TopicServer in to a common dll and just ship that dll to client.