473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Best Practice to spawn an Application from a Web Service ?

Hi all.

Can someone provide some help on the following as there seems to be many
different methods of acheiving the same outcome.

Basically I am trying to develop a web service which will spawn an exe file
to run an import and then return a result back to the web service, this
would also need the facility to spawn multiple copies of the application
upto a maximum figure..............

I think the following methods can be used but not sure all the best way....

Set IIS to interacte with the desktop and get the web service to spawn the
applicaiton and keep a global list of the process ids and an instance count?

create a com component which will spawn the application ? do i need to use
object pooling to create a list of the processids ??? not sure on this one ?
this basicaly needs to be started when the web service starts ?

help and examples would be good.....
cheers all
Nov 17 '05 #1
3 1308
Its difficult to say without knowing more about your situation but for what
there worth here are some suggestion.

1. Do not set IIS to interact with the desktop!!! I cannot think of any
reason to do this, do you expect some user to sit at the web server
interacting with the spawned application?

2. Wrap your process launching logic in its own class with a static (Shared)
variable keeping track of the number of instances launched. When your web
method launches a new instance of the process check the number of processes
currently running and handle an overflow however you want. Then increment
the number of processes variable and launch the application using the usual
methods in the Process class and wait for the process to finish. When the
process finishes decrement the number of processes variable, check the
return code for an error and handle it as necessary. IMPORTANT - the code
checking the number of instances and incrementing and decrementing would
needed to be guarded to make it thread-safe.

3. You'll need to consider what security you'll have on the web method and
on launching the process. Will the ASPNET account have sufficient
permissions to do what you want or will you need some sort of impersonation?

The following is a skeleton, off the cuff example of what you would need to
do.

'In your Web Service class.

Public Function MyWebMethod (ByVal Params??) as ??

Try
LaunchProcess (PathToProcess)
Catch ex1 As TooManyInstancesException
'Do whatever to handle this type of error.
Return failure info here
Catch ex2 As MyCustomProcessException
'Do whatever to handle this type of error.
Return failure info here
Catch ex3 as Exception
'Do whatever to handle other types of errors
Return failure info here
End Try

Return success info here

End Sub

Friend Class LaunchProcess

Private Const MAX_INSTANCES As Integer = 10
Private Const SUCCESS_CODE As Integer = 0

Private Shared m_lNumInstances As Integer
Private Shared m_objSynchObject As Object

Public Shared Sub Run(ByVal ProcessToLaunch As String)

Dim proc As Process
Dim lReturn As Integer

Try
Threading.Monitor.Enter(m_objSynchObject)
If m_lNumInstances >= MAX_INSTANCES Then
Throw New TooManyInstancesException
Else
m_lNumInstances += 1
End If
Finally
Threading.Monitor.Exit(m_objSynchObject)
End Try

proc = Process.Start(ProcessToLaunch)
proc.WaitForExit()
Threading.Interlocked.Decrement(m_lNumInstances)

lReturn = proc.ExitCode
If lReturn <> SUCCESS_CODE Then
Throw New MyCustomProcessException(lReturn)
End If

End Sub

End Class
"Paul" <ma********@hotmail.com.nospam> wrote in message
news:Ow****************@TK2MSFTNGP11.phx.gbl...
Hi all.

Can someone provide some help on the following as there seems to be many
different methods of acheiving the same outcome.

Basically I am trying to develop a web service which will spawn an exe file to run an import and then return a result back to the web service, this
would also need the facility to spawn multiple copies of the application
upto a maximum figure..............

I think the following methods can be used but not sure all the best way....
Set IIS to interacte with the desktop and get the web service to spawn the
applicaiton and keep a global list of the process ids and an instance count?
create a com component which will spawn the application ? do i need to use
object pooling to create a list of the processids ??? not sure on this one ? this basicaly needs to be started when the web service starts ?

help and examples would be good.....
cheers all

Nov 17 '05 #2
Sorry, that should be:

Public Function MyWebMethod (ByVal Params??) as ??

Try
LaunchProcess.Run(PathToProcess)
...

Nov 17 '05 #3
Hi, thanks for the response. The class that launches the process would this
have to be made a COM+ package ? As hte spawned process will be launched
within the IIS service account and then I will not be able to use the
SendKey API. Once the process is launched I need to leave it running hidden
on the host macihne and send key presses to the process in order to initiate
an import routine.
"Stephen Martin" <sm*****@removethis.emsoft.andthis.ca> wrote in message
news:uu**************@TK2MSFTNGP09.phx.gbl...
Sorry, that should be:

Public Function MyWebMethod (ByVal Params??) as ??

Try
LaunchProcess.Run(PathToProcess)
...

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
3
by: Paul | last post by:
Hi all. Can someone provide some help on the following as there seems to be many different methods of acheiving the same outcome. Basically I am trying to develop a web service which will...
2
by: Søren M. Olesen | last post by:
Hi What's best practice for distributing the load between webservices on different computers? What I'd like is for a client to always select the webservice with the least load, I.e. If...
3
by: Marc Gravell | last post by:
Kind of an open question on best-practice for smart-client design. I'd really appreciate anyones views (preferably with reasoning, but I'll take what I get...). Or if anybody has any useful links...
4
by: tshad | last post by:
I need to pass a few parameters to my Windows Service program. The end user will be changing the parameters and settings should be saved. What is the best practice - use app.config - use .ini...
4
by: richie | last post by:
Hi Everyone I have a problem with windows service I wrote which spawns a win32 program. the code in question looks like this: myProcess = new Process(); myProcess.StartInfo.FileName =...
2
by: Gabriel | last post by:
Hello, I'm looking for documentation with "Best Practice" for ASP.NET application In which case use Connected or Disconnected mode Typed dataset or not ? I didn'd find anything pertinent...
2
by: Cato | last post by:
How can i interact with a windows service written in c#? i'm developing a software that monitor file creation activity, it does work well.. it "logs" all my events and executes custom actions on...
3
by: sophie_newbie | last post by:
Hi, I'm running a python cgi script on a frontend web server and I want it to spawn another script (that takes a long time to run) on a backend number crunching server thats connected to the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.