Yesterday, I posted Windows Service Administration with ASP.NET - Part 1 - Marshalling Status Information to
show how to Marshal an object from a Windows Service to for monitoring
from an ASP.NET control. Here's how to remote to it and use it
from an ASCX control.
Step 1: Add a method to
Activate the remotable object, and return the inner class. I've
implemented this in a Business-tier class, but you can put this code
directly in your .ascx control if you wish.
public WatchListStatus GetCurrentStatus()
{
try
{
// Call GetObject to Activate our Remotable object
WatchListStatusRemotable wlsr = (WatchListStatusRemotable) Activator.GetObject(
typeof(WatchListStatusRemotable), "tcp://[SERVER]:8001/GateStatus");
// Return the inner class that contains the monitoring info
return wlsr.ServiceStatus;
}
catch(System.Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex);
System.Diagnostics.Trace.WriteLine(ex.InnerException);
return null;
}
}
Step 2: ... Is so simple, I'm not
sure I even need to explain it. Just call your Get method, and do
whatever you want with your remote object.
WatchListStatus status = GetCurrentStatus();
foreach(WatchListStatusItem item in status.StatusHistory)
{
// ... Do some cool stuff with your remote object here and amaze your friends.
}
Part 3 - Controlling your Service.
-Brendan
Music Tip - Explore a good Record Label, Like Candle Records