Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Best Practice to spawn an Application from a Web Service ?

Reply
Thread Tools

Best Practice to spawn an Application from a Web Service ?

 
 
Paul
Guest
Posts: n/a
 
      10-12-2003
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


 
Reply With Quote
 
 
 
 
Stephen Martin
Guest
Posts: n/a
 
      10-12-2003
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" <(E-Mail Removed)> wrote in message
news:OwP9p%(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Stephen Martin
Guest
Posts: n/a
 
      10-12-2003
Sorry, that should be:

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

Try
LaunchProcess.Run(PathToProcess)
...



 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      10-13-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Sorry, that should be:
>
> Public Function MyWebMethod (ByVal Params??) as ??
>
> Try
> LaunchProcess.Run(PathToProcess)
> ...
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Logging stdout/stderr/stdin of an spawn process (Open4::spawn) Edgardo Hames Ruby 1 05-06-2008 08:17 PM
Logging stdout/stderr/stdin of an spawn process (Open4::spawn) Ed Hames Ruby 0 04-16-2008 04:21 PM
Remember when your piano teacher taught you, "Practice, practice,practice ...?" Wayne Wastier Windows 64bit 3 06-10-2005 08:29 PM
spawn syntax + os.P_WAIT mode behavior + spawn stdout redirection Derek Basch Python 2 01-21-2005 05:37 AM
Best Practice to spawn an Application from a Web Service ? Paul ASP .Net 3 10-13-2003 08:13 AM



Advertisments