Monday, November 22, 2010

Check eConnect 2010 Service Status Programmatically

The number one eConnect 2010 issue that I've been asked to resolve has been the following error that I discussed back in September:

There was no endpoint listening at net.pipe://localhost/Microsoft/Dynamics/GP/eConnect/EntityOperations that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

The problem with this eConnect error is that it is useless for the average GP user, presumably because it is just a lower level WCF error being communicated up through eConnect.  Not only is it too technical, but it is misleading at best.  If a user runs your eConnect 2010 integration and sees this error, they will e-mail you or pick up the phone.  I've also found that it's useless for many GP consultants, as I've received several inquiries from consultants as well, repeatedly asking about this error.

What is frustrating is that the issue is so simple:  The error is almost always caused because the eConnect 2010 Integration Service is not running.

Unfortunately, I don't know why the service is stopping on the client servers, but since I can't directly control all of my clients' servers, I can only try and deal with the error more gracefully and give them enough information to resolve it without having to call me.

And so I wondered, can I just put some code in my integrations that can detect the status of the eConnect 2010 service before I even try and call it?  I've never tried checking the status of a Windows service, and although I assumed it was possible, I didn't know how difficult it would be.  Well, after receiving yet another e-mail about this issue tonight, I finally took a few seconds and read how to detect the status of a Windows service using .NET.

This great tutorial article told me all that I needed to know to check the service status in less than 60 seconds.

It's wonderfully simple--in just a few lines of code, you can tell if the eConnect 2010 service is running. Here is a basic example:

ServiceController byConstructor = new ServiceController("DynGP11eConnect");

if (byConstructor.Status != ServiceControllerStatus.Running)
    MessageBox.Show("The eConnect 2010 Integration service is NOT running.");
    MessageBox.Show("The eConnect 2010 Integration service IS running.");

Other than those few lines, just make sure to add a reference to System.ServiceProcess, and then add using System.ServiceProcess; to your class.

It's that easy!

I would personally recommend adding this service status check to any eConnect 2010 integration.  I'll be adding it to my standard Functions library that I use with all of my integrations.

Steve Endow is a Dynamics GP Certified Trainer and Dynamics GP Certified Professional.  He is also the owner of Precipio Services, which provides Dynamics GP integrations, customizations, and automation solutions.

No comments: