How to call a Batch Job from a WCF Service via Silverlight client call

Feb 26, 2012 at 4:22 AM

Hi, 

Context: 

We have a front end application in Silverlight 4.0 and the middle tier as a WCF 4.0 service (IIS hosting). 

Environment (Sand Box): 

Windows XP SP3

IIS 5.1

.Net Framework 4.0

VS-2010 

Problem Statement: 

We want to execute a batch job (*.bat) on the server through the WCF Service (operation contract). This batch job needs to be executed when the user trigger some event (say button click) from the front end (Silverlight). 

I am doing this through  “System.Diagnostics.Process” class (see the below code snip set). But I am getting an error: 

 “The application failed to initialize properly (0xc0000142). Click on OK to terminate the application. 

I am already done some research using google but didn’t find any solution. Also, I have tried the following things: 

  • Giving Full trust to the WCF service hosted in the IIS.
  • User “Test” with which I am executing the batch job is having Admin access on the machine.
  • Giving Full control to the user account (Test) on the file system containing the batch job.
  • Giving Full control to the “ASPNET” account on the file system containing the batch job.
  • Giving Full control to the “IUSR_MachineName” account on the file system containing the batch job.

 What is required from You: 

  1. What is the best way in terms of architecture to call the batch job on some client action via  WCF service.
  2. If anybody has implemented the similar scenario then please provide some pointers.

 Code: 

public void ExecuteBatchJob()

        {

            try

            {

                char[] chars = { 't', 'e', 's', 't', '$', '1', '$', '$', '$' };

                SecureString securePwd = new SecureString();

                foreach (char ch in chars)

                    securePwd.AppendChar(ch); 

                Process objProcess = new Process(); 

                objProcess.StartInfo.UseShellExecute = false;

                objProcess.StartInfo.WorkingDirectory = @"C:\Inetpub\wwwroot";

                objProcess.StartInfo.FileName = @"C:\WINDOWS\system32\cmd.exe";

                objProcess.StartInfo.CreateNoWindow = true;

                objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

                objProcess.StartInfo.Arguments = @"/C C:\Inetpub\wwwroot\Test.bat";

                objProcess.StartInfo.UserName = "Test";

                objProcess.StartInfo.Password = securePwd;

                objProcess.StartInfo.Domain = "XYZ";               

                objProcess.Start(); 

            }

            catch (Exception ex)

            {

            }

        } 

Thanks.

Prateek