Best Practice to spawn an Application from a Web Service ?

Discussion in 'ASP .Net Web Services' started by Paul, Oct 12, 2003.

  1. Paul

    Paul Guest

    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
     
    Paul, Oct 12, 2003
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:OwP9p%...
    > 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
    >
    >
     
    Stephen Martin, Oct 12, 2003
    #2
    1. Advertising

  3. Sorry, that should be:

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

    Try
    LaunchProcess.Run(PathToProcess)
    ...
     
    Stephen Martin, Oct 12, 2003
    #3
  4. Paul

    Paul Guest

    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" <> wrote in message
    news:...
    > Sorry, that should be:
    >
    > Public Function MyWebMethod (ByVal Params??) as ??
    >
    > Try
    > LaunchProcess.Run(PathToProcess)
    > ...
    >
    >
    >
     
    Paul, Oct 13, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul
    Replies:
    3
    Views:
    426
  2. Derek Basch
    Replies:
    2
    Views:
    1,321
    Donn Cave
    Jan 21, 2005
  3. Tal McMahon

    Best Practice for referencing datasets with web service

    Tal McMahon, Aug 6, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    101
    Tal McMahon
    Aug 6, 2003
  4. Ed Hames
    Replies:
    0
    Views:
    389
    Ed Hames
    Apr 16, 2008
  5. Edgardo Hames
    Replies:
    1
    Views:
    373
    Ed Hames
    May 6, 2008
Loading...

Share This Page