Problem using remote controls
- From: "ThunderMusic" <NoSpAmdanlatathotmaildotcom@xxxxxxxxxx>
- Date: Fri, 5 Jan 2007 11:10:58 -0500
Hi,
(I'll put all the code at the end of the post)
I have an 2 applications : 1 server and 1 client. The server creates an
instance of a class and marshals it. This class has a method called
GetControl() which returns the control to display the informations of the
class. I know the names are awful for now, but it was for testing purpose
before doing the real thing... ;) The client then get the object (the
class) from the server and calls the GetControl() method. The control gets
to the client right, I can set properties, call methods and everything...
the problem is, I can't add it to the control collection of my form
(myForm.Controls.Add(ctl)). I receive this message : "Permission denied:
cannot call non-public or static methods remotely." I'm not calling any
non-public nor static methods, but I understand the code behind
myForm.Controls.Add does... Is there a way I can get around this? I'm
using .Net 2.0 (could eventually go to using 3.0 if this is what it takes).
Thanks
ThunderMusic
{Here's the code}
Project 1 : Interfaces (which in the end are only abstract classes) :
File 1 : BaseClass.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Interfaces
{
public abstract class BaseClass : MarshalByRefObject
{
public abstract BaseControl GetControl();
}
}
File 2 : BaseControl.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Interfaces
{
public abstract class BaseControl : System.Windows.Forms.Control
{
}
}
Project 2 : Classes (which really contains the implementation of the classes
the server will marshal) :
File 1 : TestClass.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Classes
{
public class TestClass : Interfaces.BaseClass
{
public override Interfaces.BaseControl GetControl()
{
return new TestControl();
}
}
}
File 2 : TestControl.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Classes
{
public class TestControl : Interfaces.BaseControl
{
protected override void OnPaint(System.Windows.Forms.PaintEventArgs
e)
{
e.Graphics.DrawString("This is it... I got it...", new
System.Drawing.Font("Arial", 10), new
System.Drawing.SolidBrush(System.Drawing.Color.Black),0,0);
}
}
}
Project 3 : TestRemotingServer (Console app for the server, but could be a
Windows Service)
File 1 : Program.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
namespace TestRemotingServer
{
class Program
{
static void Main(string[] args)
{
Classes.TestClass tc = new Classes.TestClass();
RemotingConfiguration.Configure(AppDomain.CurrentDomain.BaseDirectory
+ "TestRemotingServer.Remoting.config",true);
RemotingServices.Marshal(tc, "testclass");
Console.Write("Press any key to continue."); Console.ReadLine();
}
}
}
File 2 : TestRemotingServer.Remoting.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" ID="TestRemotingServer" secure="true"
port="21234" tokenImpersonationLevel="Impersonation" impersonate="true"
protectionLevel="EncryptAndSign">
<clientProviders>
<formatter ref="binary"/>
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"/>
</serverProviders>
</channel>
</channels>
</application>
<customErrors mode="Off" />
</system.runtime.remoting>
</configuration>
Project 4 : TestRemoting (The client application) :
File 1 : Form1.cs
using System;
using System.Runtime.Remoting;
using System.Windows.Forms;
namespace TestRemoting
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
RemotingConfiguration.Configure(AppDomain.CurrentDomain.BaseDirectory
+ "TestRemoting.Remoting.config", true);
Interfaces.BaseClass obj =
(Interfaces.BaseClass)Activator.GetObject(typeof(Interfaces.BaseClass),
"tcp://127.0.0.1:21234/testclass");
// Get the control and add it to the form.
Control ctl = obj.GetControl();
ctl.Location = new Point(10, 10);
ctl.Size = new Size(150, 50);
this.Controls.Add(ctl);
}
}
}
File 2 : TestRemoting.Remoting.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" ID="TestRemoting" secure="true" Port="0"
tokenImpersonationLevel="Impersonation" impersonate="true"
protectionLevel="EncryptAndSign">
<clientProviders>
<formatter ref="binary"/>
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"/>
</serverProviders>
</channel>>
</channels>
</application>
<customErrors mode="On" />
</system.runtime.remoting>
</configuration>
{Code Done}
.
- Prev by Date: Re: Chating application which incorporates voice (voip)
- Next by Date: Re: Raise event to client
- Previous by thread: Raise event to client
- Next by thread: Re: Error while invoking remoteobject method
- Index(es):
Relevant Pages
|