简体   繁体   中英

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.

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 (eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM