ccStars
ccStars

Reputation: 815

Calling an EXE from a WCF Service

I am working on a project where i need to run an executable once its reached the end of the WCF Method, I cant do this in the codebehind as the webservice will be set to oneway.

I have tried the following:

  System.Diagnostics.Process process = new System.Diagnostics.Process();

  System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
  startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
  startInfo.FileName = "C:\\Test.exe";
  startInfo.Arguments = "Arg";
  process.StartInfo = startInfo;
  process.Start();

The WCF webservice doesn't throw any errors.

Is it possible to call executables from WCF or is there any alternative ways of doing this.

Upvotes: 1

Views: 2905

Answers (1)

John Wu
John Wu

Reputation: 52240

The main difference between double clicking a program versus launching it from your WCF service is permissions. When you double click the program, it runs under your account (which is probably administrator or super user) while launching from the WCF service will execute it under the service account associated with the WCF application or the app pool in which it resides (which is typically very restricted).

To test to see if this is the problem, ON DEV BOX ONLY, you can temporarily assign administrator as the app pool service account and see if it works. Once you have confirmed that is the problem, restore the original account and tweak its permissions until the program works.

Another way to test it is to interactively sign on as the IIS account and double click the program. This will let you see any errors that may be occurring when it is called from the service.

There are other potential problems (e.g. environment variables or current working directory that are different when running as yourself vs. as the WCF service) but I've found that permissions is usually the culprit.

Upvotes: 2

Related Questions