Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Friends,

Need your help. I have a scenario where I need to call a webservice hosted on a database server in DMZ, from a client console application.The webservice should start a batch file, locally on database server, which calls some package and when the processing of that package is finished batch file should inform Console Client application about it. For my testing purpose I have written the below code

string target = @"c:\Test Batch.bat";
Process proc = new Process();
proc.StartInfo.FileName = target;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.Exited += new EventHandler(proc_Exited);
proc.EnableRaisingEvents = true;
proc.Start();
proc.WaitForExit();

I also created a webservice locally and i am able to start the batch file via webservice call. Since I need to report back to client that batch file is finished, I used Asyn method, and registered for the onCompleted event of the webservice. But here is my problem, the OnCompleted event is not fired :(
What should i do to get it working ?

Also if my batch file is runnig some other EXE which takes about 2 hours to finish, the process class wait for 2 hours till the time EXE is finished or it exits when the batch file has started the EXE, and dont wait for it to finish ?

One other question, which authentication mode should be used to secure web service as the database server is on DMZ ?

Many thanks if all my questions are answered. Regards!



"Confidence does not come when you all the answers, It comes when you are ready to face all the questions"
Posted

1 solution

Don't do it. You already use a blocking call WaitForExit. You will be done when this call is finished. All you need is to run this code in a separate thread. Generally, using threads is better and makes all asynchronous API redundant. In this case, too: don't use Exited event.

—SA
 
Share this answer
 
Comments
netnest 4-Jul-11 2:34am    
Thanks for your reply SAKryukov. It is good that i know now the WaitForExit will inform me when the batch processing is finished, but if we are making call asynchronously to webservice, then how will I know that Batch processing has finished ?
Sergey Alexandrovich Kryukov 5-Jul-11 0:37am    
A call to Webservice is not a launch of application, this is HTTP request and response, so this is all not applicable. When you read the response from the network stream, you're done. You're not waiting for any process.

Now, about asynchronous calls (in case of webservice this is not a call at all, but conceptually similar, one the forms of remote call, RPC). Asynchronous APIs were invented when multithreading was not introduces or poorly used by developers. I would always prefer synchronous API but did all the operations based on blocking call in a separate thread. For both Service and UI applications it's a must anyway, not just by this reason.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900