.NETGURU
Remoting and calling functions in another class
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.csharp.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Mark
What I want to do is call a function in my main form/class from the
server (which the another program/client calls). The main form does
not really create a server object so I can't pass the frmForm class
into the constructor of MyServer (the client side would have no idea
what to pass into that anyways). What other way to do this is there?
I guess there is static functions, but I can't make everything in
those functions static.

namespace Mark
{
public class frmForm : System.Windows.Forms.Form
{
private void frmForm_Load(object sender, System.EventArgs e)
{
HttpChannel channel = new HttpChannel(8001); //Create a new
channel
ChannelServices.RegisterChannel (channel); //Register channel
RemotingConfiguration.RegisterWellKnownServiceType(typeof                (MyServer),"MyServer",WellKnownObjectMode.Singleton);
}
public void Function1()
{
//do some non-static stuff here
}
}

public class MyServer: MarshalByRefObject
{
public void CalledByClient()
{
//want to call frmForm.Function1 here
}
}
}
Reply to this message...
 
    
Richard Blewett
Well MyServer is a singleton how about getting the form to achieve the same
effect by manually marshallingobject into the remoting infrastructure.

instead of using RegisterWellKnownServicetype, create an instance of
MyServer pass itself into the ctor and then call
RemotingServices.Marshal passing the instance.

Its proably a good idea in this case to override InitializeLifetimeServices
in MyServer and return null. This will disable the lease based distributed
garbage collection of remoting which in this case is probably a good idea.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

"Mark" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Mark
"Richard Blewett" <Click here to reveal e-mail address> wrote in message news:<Click here to reveal e-mail address>...
[Original message clipped]

So would I do something like?

MyServer svr = new MyServer();
svr.PassFormOver(this);
ObjRef objrefWellKnown = RemotingServices.Marshal(svr, ???????);

What do I put for the other arguments?

I would of course put something like

public class MyServer: MarshalByRefObject
{
static public Mark.frmForm frmMyForm;

public void PassFormOver(Mark.frmForm frm)
{
frmMyForm = frm;
}

public void CalledByClient()
{
//want to call frmForm.Function1 here
}
}
}
Reply to this message...
 
    
Richard Blewett
HttpChannel channel = new HttpChannel(8001);
MyServer ms = new MyServer(this);
RemotingServices.Marshal(ms, "MyServer");
ChannelServices.RegisterChannel (channel); //Register channel

you basically provide the same info as with RegisterWellKnownServiceType but
*you* create the instance rather than the remoting infrastructure. And as
you can see I'd probably create a ctor on MyServer which took an instance of
your form.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

"Mark" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Mark
That seems to work. Thanks. One more question though. How does it
know it's a singleton? Sorry if it's a rookie question but this is my
first time working with remoting. Does it also already know it's a
WellKnownServiceType?

"Richard Blewett" <Click here to reveal e-mail address> wrote in message news:<uYfkC#Click here to reveal e-mail address>...
[Original message clipped]

Reply to this message...
 
    
Richard Blewett [DevelopMentor] (VIP)
You do not give responsibility to the remoting infrastructure for object
ceration therefore if you only marshal one instance to the remoting
infrastructure it will be a singleton in effect.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

"Mark" wrote:

[Original message clipped]

Reply to this message...
 
 
System.EventArgs
System.MarshalByRefObject
System.Runtime.Remoting.Channels.ChannelServices
System.Runtime.Remoting.Channels.Http.HttpChannel
System.Runtime.Remoting.ObjRef
System.Runtime.Remoting.RemotingConfiguration
System.Runtime.Remoting.RemotingServices
System.Runtime.Remoting.WellKnownObjectMode
System.Windows.Forms.Form




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification