• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

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");



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.
1 Solution
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.

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now