locked
How do I design singleton webservice?

    Question

  • Hi,

    My design requirement is to have webservice which will shall be executing only 1 instance of it. I have to receive updates in web browser about progress of execution and not launch second instance unless webservice is idle.
    1. Is there something withing .NET framework which will allow me to do that or I have to create complicated wrappers to achieve that?
    2. How do I get updates about results of webservice state of execution (create static fields and pull them out from another service or how?).

    Thanks,
    G
    • Moved by nobugzMVP, Moderator Tuesday, March 10, 2009 3:07 PM not a clr q (Moved from Common Language Runtime to ASMX Web Services and XML Serialization)
    Tuesday, March 10, 2009 2:09 PM

Answers

  • You would restrict the instancing on the back end. However, you might find that you don't need to restrict it. With WCF and WF, I believe you can arrange to have subsequent (progress) requests always come in to the correct WF instance. You could have several instances running at the same time, without confusion. Also, depending on how the long-running task works, you might not be tying up any resources while the long-running task runs. For instance, if it were a long-running database query or update, WF will not be blocked waiting for it.

    One strategy I would suggest is to get trial versions of Windows Server 2008 and SQL Server 2008 running on a virtual machine, ASAP. Note that you do not need to use all the new features - treat them like the old versions, picking up on the features that solve the problems you've had for years. For instance, you'll like the Event Viewer in Server 2008 (you can resize the event properties dialog!), and you'll love being able to use PowerShell to maintain SQL Server databases and tables, pretty much just as though they were parts of the file system.

    After a while of seeing you use these features, management may begin to wonder what they were waiting for.
    John Saunders
    Use File->New Project to create Web Service Projects
    Use WCF for All New Web Service Development, instead of old ASMX or obsolete WSE
    Tuesday, March 10, 2009 3:51 PM
    Moderator

All replies

  • Sorry, you've hit another feature of WCF that ASMX does not implement. You have no control over instances.

    When you talk about retrieving the results of the state of execution, are you thinking that your service will have some long-running calls? What intermediate state would you want?

    Yes, the typical way to do this (if you absolutely must do it) is to save the execution state in static members (with appropriate locking), and to have another service interrogate the members.
    John Saunders
    Use File->New Project to create Web Service Projects
    Use WCF for All New Web Service Development, instead of old ASMX or obsolete WSE
    Tuesday, March 10, 2009 3:20 PM
    Moderator
  • Yes my service will have some long running method execution for up to 2 hours and I need to now intermediate state it's in. (I assume there is better way to accomplish this then to run inside webservice process? WF service instead of it? Or how if I need to have long running call (I'm pulling Gigs of data from internet via FTP and HTTP to local storage)
    If I run it inside WCF I'll be able to restrict to only one instance of service to be instantiate at any given time?
    Tuesday, March 10, 2009 3:26 PM
  • If you need a long-running process, then you should consider creating a Workflow Service running in WCF. Since you're stuck on .NET 2.0, you can't do that. See what you miss out on when you run ten year-old technology? :-)

    The .NET 2.0 way to handle this is to have the long-running process execute in a Windows Service, scheduled task, SQL Server Agent Job, or something like that. Have the web service initiate the long-running process. If only one instance of the process can run at a time, allow the web service to queue up requests to the long-running process using MSMQ. The process could then take one request at a time. The long-running process could report intermediate results (if any) using a file, or MSMQ, or any other mechanism that would permit the werb service to see the progress. The service would have a second call to check progress, and it would inspect the intermediate results.


    John Saunders
    Use File->New Project to create Web Service Projects
    Use WCF for All New Web Service Development, instead of old ASMX or obsolete WSE
    Tuesday, March 10, 2009 3:31 PM
    Moderator
  •  If I somehow convince people to upgrade to .NET 3.5 SP1. So design pattern for this application will be WCF front end to provide updates and manage backend and WF service on back end running long running method. Where do I restrict singleton pattern then in front-end or back-end or is it possible to do in a first place?

    Thanks,
    G
    Tuesday, March 10, 2009 3:36 PM
  • You would restrict the instancing on the back end. However, you might find that you don't need to restrict it. With WCF and WF, I believe you can arrange to have subsequent (progress) requests always come in to the correct WF instance. You could have several instances running at the same time, without confusion. Also, depending on how the long-running task works, you might not be tying up any resources while the long-running task runs. For instance, if it were a long-running database query or update, WF will not be blocked waiting for it.

    One strategy I would suggest is to get trial versions of Windows Server 2008 and SQL Server 2008 running on a virtual machine, ASAP. Note that you do not need to use all the new features - treat them like the old versions, picking up on the features that solve the problems you've had for years. For instance, you'll like the Event Viewer in Server 2008 (you can resize the event properties dialog!), and you'll love being able to use PowerShell to maintain SQL Server databases and tables, pretty much just as though they were parts of the file system.

    After a while of seeing you use these features, management may begin to wonder what they were waiting for.
    John Saunders
    Use File->New Project to create Web Service Projects
    Use WCF for All New Web Service Development, instead of old ASMX or obsolete WSE
    Tuesday, March 10, 2009 3:51 PM
    Moderator