Simple remoting call fails from windows service, but not from console app. Why?

I have a Windows Forms application on a server.  It has a PeizoGreeter object, which is meant to be a remote object which waits for a store to pass it's store number to it (via AnnounceStoreName).
 

    class PeizoGreeter : MarshalByRefObject
    {
        // the GUI listens for remote calls with these
        public delegate void PeizoPullEventHandler(object sender, PeizoPullEventArgs e);
        public event PeizoPullEventHandler PeizoPullEvent;
                               
        public PeizoGreeter()
        {
            // dont need anything here for now...
        }


        // allows object to live forever
        public override object InitializeLifetimeService()
        {
            return null;
        }


        public void AnnounceStoreName(int storeNumber)
        {
            // inform the GUI that this was called
            if (PeizoPullEvent != null)
                PeizoPullEvent(this, new PeizoPullEventArgs(storeNumber));
        }

 

I also have a Windows Service.  This service waits for a condition to occur, then creates a connection to the remote object and calls AnnounceStoreName, as follows:

ChannelServices.RegisterChannel(new TcpChannel(), true);

PeizoGreeter rmGreeter = new PeizoGreeter();
rmGreeter = (PeizoGreeter)Activator.GetObject(typeof(PeizoGreeter), "tcp://myipaddress:myport/PeizoGreeter");

rmGreeter.AnnounceStoreName(45);

 

However, when I attempt to do this, the code fails on the line rmGreeter.AnnounceStoreName, and I get the following Exception and InnerException messages:

Value cannot be null.
Error: Object reference not set to an instance of an object.

I don't understand why this is happening.  I took the EXACT same code and plopped it into a console application, and it made the remote function call fine!  Why would my windows service (installed with administrator rights) not be able to make this remote call?  Clearly, the object is not getting the reference to the remote object.

Any help would be greatly appreciated!!!!  After hours of trial and error I am completely stumped.
SkkraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TribmosCommented:
Most services run as "SYSTEM" which is a local authenticated account.

The console is most likely running as your USER.

Not sure if your on a domain or not, but there is a difference in permissions that is most likely causing the issue.

I suggest you put some try/catch around aspects and rerun the service and write the exceptions to the event log.  At least that is the best way I have found to troubleshoot problems with a service.

http://support.microsoft.com/kb/307024  (writing to event log in C#)

What does "AnnounceStoreName" do?  Does it "interact with the desktop"? if so that will need to be enabled on the service.  In fact that might be one thing to try easily.

<Service properties> -> Log On -> Allow service to interact with desktop
Could also try the "this account" and supply credentials

If the service works when run as your account but not as system then its a permissions issue
If it runs as system account with desktop interaction then you may need to update your service installer to include that.

What could be happening is that its trying to go out (or do something) on the network before the client network stuffs are fullly loaded.  Thus they are null and fail.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.