DaFou
asked on
Remoting
Ola,
I have this book on .NET networking and it has an example of remoting.
In the example I created a client ( winForm ), a remotingObject ( classlib ) and a server ( win service ).
the client sets up the remote object with type of the RemoteObject and it connects to the server.
The server has already setup a ChannelService and listens for incomming procedure calls to the remote object.
The remote object now returns some integer to the client.
But this is not what I want to do. I want the client to invoke a method from the server and pass it some parameter.
how do i adjust my code?
//client ( winform )
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Ch annels;
using System.Runtime.Remoting.Ch annels.Htt p;
using RemoteObject;
namespace RemoteClient
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Butto n button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Cont ainer components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Butto n();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(24, 24);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.b utton1_Cli ck);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.but ton1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
RemoteObject.IDGenerator remObject = (RemoteObject.IDGenerator) Activator. GetObject(
typeof(RemoteObject.IDGene rator),
"http://localhost:8085/RemotingServer"
);
System.Windows.Forms.Messa geBox.Show ( Convert.ToString( remObject.getID() ) );
}
}
}
// Remote Object ( Class Library )
using System;
namespace RemoteObject
{
public class IDGenerator : System.MarshalByRefObject
{
private int lastID = 0;
public int getID()
{
return( lastID++ );
}
}
}
// Server ( windows service )
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Configuration.Insta ll;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Ch annels;
using System.Runtime.Remoting.Ch annels.Htt p;
using System.Threading;
namespace RemoteService
{
public class Service1 : System.ServiceProcess.Serv iceBase
{
private System.ComponentModel.Cont ainer components = null;
public Service1()
{
InitializeComponent();
}
static void Main()
{
System.ServiceProcess.Serv iceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.Serv iceBase[] { new Service1() };
System.ServiceProcess.Serv iceBase.Ru n(Services ToRun);
}
private void InitializeComponent()
{
components = new System.ComponentModel.Cont ainer();
this.ServiceName = "Service1";
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
Thread thdServer;
protected override void OnStart(string[] args)
{
thdServer = new Thread( new ThreadStart( serverThread ) );
thdServer.Start();
}
protected override void OnStop()
{
thdServer.Abort();
}
public void serverThread()
{
HttpChannel channel = new HttpChannel( 8085 );
ChannelServices.RegisterCh annel( channel );
RemotingConfiguration.Regi sterWellKn ownService Type(
typeof( RemoteObject.IDGenerator ),
"RemotingServer",
WellKnownObjectMode.Single ton
);
}
// method that should be called from a client.
public void DoSomething()
{}
}
}
I have this book on .NET networking and it has an example of remoting.
In the example I created a client ( winForm ), a remotingObject ( classlib ) and a server ( win service ).
the client sets up the remote object with type of the RemoteObject and it connects to the server.
The server has already setup a ChannelService and listens for incomming procedure calls to the remote object.
The remote object now returns some integer to the client.
But this is not what I want to do. I want the client to invoke a method from the server and pass it some parameter.
how do i adjust my code?
//client ( winform )
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Ch
using System.Runtime.Remoting.Ch
using RemoteObject;
namespace RemoteClient
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Butto
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Cont
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Butto
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(24, 24);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.b
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.but
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
RemoteObject.IDGenerator remObject = (RemoteObject.IDGenerator)
typeof(RemoteObject.IDGene
"http://localhost:8085/RemotingServer"
);
System.Windows.Forms.Messa
}
}
}
// Remote Object ( Class Library )
using System;
namespace RemoteObject
{
public class IDGenerator : System.MarshalByRefObject
{
private int lastID = 0;
public int getID()
{
return( lastID++ );
}
}
}
// Server ( windows service )
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Configuration.Insta
using System.Runtime.Remoting;
using System.Runtime.Remoting.Ch
using System.Runtime.Remoting.Ch
using System.Threading;
namespace RemoteService
{
public class Service1 : System.ServiceProcess.Serv
{
private System.ComponentModel.Cont
public Service1()
{
InitializeComponent();
}
static void Main()
{
System.ServiceProcess.Serv
ServicesToRun = new System.ServiceProcess.Serv
System.ServiceProcess.Serv
}
private void InitializeComponent()
{
components = new System.ComponentModel.Cont
this.ServiceName = "Service1";
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
Thread thdServer;
protected override void OnStart(string[] args)
{
thdServer = new Thread( new ThreadStart( serverThread ) );
thdServer.Start();
}
protected override void OnStop()
{
thdServer.Abort();
}
public void serverThread()
{
HttpChannel channel = new HttpChannel( 8085 );
ChannelServices.RegisterCh
RemotingConfiguration.Regi
typeof( RemoteObject.IDGenerator ),
"RemotingServer",
WellKnownObjectMode.Single
);
}
// method that should be called from a client.
public void DoSomething()
{}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i was too fast in accepting your answer :-(
I am unable to make the server component is such a way that it is a windows service. But i really need it to be a windows service.
please show me how to make it a service.
I am unable to make the server component is such a way that it is a windows service. But i really need it to be a windows service.
please show me how to make it a service.
Creating a service is not too far once you have an execuatable...
Here are the steps that I take...
1) If your server assembly is not a dll change it to be a dll.
2) Create a new C# Windows Service project in your solution... I called mine ProjService
3) Modify the class to start your application... There are plunty of comments in the class to help you here...
4) Open up in help ServiceProcessInstaller for complete directions to finish...
NOTE: You will want to do the installer, it makes things much easier...
Here are the steps that I take...
1) If your server assembly is not a dll change it to be a dll.
2) Create a new C# Windows Service project in your solution... I called mine ProjService
3) Modify the class to start your application... There are plunty of comments in the class to help you here...
4) Open up in help ServiceProcessInstaller for complete directions to finish...
NOTE: You will want to do the installer, it makes things much easier...
ASKER
I have no clue what you mean..
please help out on this 500 points question
https://www.experts-exchange.com/questions/21098923/NET-Remoting-to-a-windows-service-in-NET.html
please help out on this 500 points question
https://www.experts-exchange.com/questions/21098923/NET-Remoting-to-a-windows-service-in-NET.html
ASKER
Hi NipNFriar_Tuck
https://www.experts-exchange.com/questions/21116444/C-Remoting.html
https://www.experts-exchange.com/questions/21117316/Help-on-remoting.html
Here are 2 identical ( yet asked different ) questions.
The latterone is near completion. If you could fix that one the other 500 points could be easily taken by copy pasting the solution of the latter in the first question.
I am sorry i have to flud EE with questions on remoting :-(
I hope you can help some more.
https://www.experts-exchange.com/questions/21116444/C-Remoting.html
https://www.experts-exchange.com/questions/21117316/Help-on-remoting.html
Here are 2 identical ( yet asked different ) questions.
The latterone is near completion. If you could fix that one the other 500 points could be easily taken by copy pasting the solution of the latter in the first question.
I am sorry i have to flud EE with questions on remoting :-(
I hope you can help some more.
ASKER