There will be a question in here so stay with me, I'm providing some background first.
I just started working on an existing app with the programmer that originally wrote the code. My contribution will be to make one instance of the app running on one workstation on a network talk to another instance of the same app running on a different workstation on the network.
To provide the services I want to use .NET Remoting (eventually Web Services for more flexibility) so I've created a class derived from MarshalByRefObject. I've compiled this class into the existing app.
Most of the documentation on MSDN for .NET remoting gives examples of the service as part of a DLL. I want my service to be part of the existing EXE. This EXE will also act as a client on another workstation.
How do I configure the server and client configuration files so the client can access the service class of the app running in the instance on the "server" workstation
This seams to be a more advanced approach than those described in the MSDN documentation. Is there documentation (MSDN, books, mag articles, or otherwise) that would address something like this
Thanks, Mike.

Can .NET Remoting App be both Client and Server?
Mrs RP
change has been made in above code!
Ted69
We must provide a proof of concept that one instance of the app can talk to another instance of the app on different workstations over a network. No requirements have been specified yet as to the services that should be provided, so for the proof of concept the development team decided that two services need to be demonstrated. One that a clinet instance of the app can ask the server instance for a list of task names in it's current workflow and two, ask what the current status of any of those tasks is. Conversly we would like the client to be able to provide the same service, as a server, to an instance that was previously described as a server, acting as a client.
In short, the app has to be able to act as both client and server.
In the future, we would like other workflow apps, developed for other platforms that we can not control to have access to our apps services. This is where I will be architecting a Web Service service (or converting our proof of concept service to Web Services if the functionality we provided meets requirements).
So I have created a services class that I would like the client to access as a object on the server instance and the converse using .NET Remoting.
I understand the MSDN remoting code for the service object, client and server. What I need to know is how to configure the app to be both client and server usnig a configuration file (either programatically or external config file).
Thanks for the reference book, I've been considering buying it. Do you know if it addresses this issue specifically
Thanks Mike.
ROK15955
For example assume the following:
class MyRemote : MarshalByRefObject
{
}
If this class is part of an executable that can be both a client and a server then when an instance of this class is created by the client code wouldn't an instance be created on the client not on the server since there is a local definition of the class to instantiate
For example in the client code of the app:
MyRemote remote = new Remote( );
remote should be created on the server and accessed through a proxy on the client, but since the app can be both client and server would remote actually be created on the client since the class is defined in a single app that can be both client and server
Mike
Andreas Hammar
I have not had a chance to review it in detail yet. I will do that tonight when I get home. I'm also going to try a few things of my own.
I'll post again tomorrow.
5783sguitar
I am going to do this in 1.1 as thats what I am configured for right now
chris can surf
a class is just a data type (code).
an object is an instance of a class.
You don't remote a class - you remote an object, which happens to be of some class type.
for each remoted object your app uses the configuration file specifies a remote objects type, its location, and its role/lifetime.
We can 'touch' an object, you can only 'describe' a class
What makes an app a client is that a client initiates the communication with the server responds. It makes no implication as to how much work is done.
that being said. the simple answer is yes. An instance of an exe can initiate communication with an instance of an object in an instance of any other app (even itself) as long as the object is configured properly on both sides.
I guess my question would be, what do you want do
do you want both instances of the exe to share a single instance of an object do you want both instances of the app to have a server instance and a client instance do you want an instance of an app to present an API that other instances of the app can talk to
Give a little background describing what your functional goal is.
why do you not want to put the class in a seperate assembly
are web services really more flexible
the remoting bible:
http://www.apress.com/book/bookDisplay.html bID=47
wgkwvl
when my girlfriend goes to work I will hammer out an example (if no one else does in the meantime)
kim aldis
I just needed two things, confirmation and an example of what the configs look like.
Thanks for the help.
Any more comments on the book
Mike
Maarten van Stam
But the book is definitely worth picking up. It blows away the microsoft press .Net Remoting.
As a rule, I have been totally disappointed with almost every microsoft press book I own.
Emin
ok. .. does this make sense to you:
here are some sample taskmanager/task class. . . note the static getinstance that takes a host name as an argument:
also has a delegate with a signature for the getinstance method. . . this allows for asynchronous retrieval of a taskmanager
================
public class TaskManager:MarshalByRefObject
{
IList _list = new ArrayList();
public TaskManager()
{
this._list.Add(new Task());
this._list.Add(new Task());
this._list.Add(new Task());
this._list.Add(new Task());
}
public IList ManagedTasks
{
get
{
return _list;
}
}
public static TaskManager GetInstance(string host)
{
return (TaskManager) Activator.GetObject(typeof(TaskManager),
string.Format(@"tcp://{0}:1234/taskmanager.rem",host));
}
}
public delegate TaskManager GetInstanceDelegate(string host);
public class Task: MarshalByRefObject
{
Guid _id = Guid.NewGuid();
TaskStatus _status = TaskStatus.Ready;
public Guid ID
{
get
{
return _id;
}
}
public TaskStatus Status
{
get
{
return _status;
}
set
{
_status = value;
}
}
}
public enum TaskStatus
{
Ready, Steady, Go,
}
in your main form drop a datagrid on the grid, call it datagrid1.
put this code in your form1 (note the asynchronous call to TaskManager.GetInstance. this allows the apps current thread to relenquish control in case the host is "localhost" ):
private void GetManagedTasksFromHost(string host)
{
GetInstanceDelegate del = new GetInstanceDelegate(TaskManager.GetInstance);
IAsyncResult ar = del.BeginInvoke(host, null, null);
System.Threading.Thread.Sleep(0);
TaskManager obj = del.EndInvoke(ar);
dataGrid1.DataSource = obj.ManagedTasks;
}
declare a local TaskManager variable and override OnLoad (note the call to load the grid from itself!!!)
TaskManager _manager;
protected override void OnLoad(EventArgs e)
{
/* set up the service!!! */
BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary props = new Hashtable();
props["port"] = 1234;
TcpChannel chnl = new TcpChannel(props, null, provider);
ChannelServices.RegisterChannel(chnl);
RemotingServices.Marshal(_manager, "taskmanager.rem");
/* load the apps task manager!!! */
GetManagedTasksFromHost("localhost");
base.OnLoad (e);
}
all you have to do to change the grid to another host is propmt the user for a host name and call GetManagedTasksFromHost and booyah!!! the grid displays the other hosts tasklists!
I haven't figured out how to configure the service via a config file. . .everything I tried failed!