Request specific singleton in webservice ?

Discussion in 'ASP .Net Web Services' started by Poul Lund J?rgensen, May 28, 2004.

  1. Hi,

    I would like to use the singleton pattern in a webservice in order to
    ensure one and only one instance of certains objects within the
    context of the webservice request.

    When I try to build the usual singleton pattern with the static
    instance variable I notice that the static member is shared between
    different webservice call which is NOT what I want.

    I am considering using the HttpContext.Current.Items dictonary as a
    kind of webservice local singleton storage in order to avoid the
    singletons being shared between webservice call, but it would require
    a lot refactoring in the current application.

    Does anyone know a better way to obtain webservice locale singletons ?

    best regards
    Poul Lund Jørgensen
     
    Poul Lund J?rgensen, May 28, 2004
    #1
    1. Advertising

  2. You'll have to use static variables or maintain an index / collection
    that's shared in your web service call. Start by thinking what objects
    are created and then destroyed by the SOAP / web service calls, independent
    of other calls.

    Maybe you would want to store this variable in the WebService.Context
    object (of type System.Web.HttpContext) which is created for the request.
    Check out the "Items" collection member variable.

    --
    CharlieN
    DevDiv

    This posting is provided "AS IS" with no warranties, and confers no rights.

    Note: For the benefit of the community-at-large, all responses to this
    message are best directed to the newsgroup/thread from which they
    originated.

    --------------------
    > From: (Poul Lund J?rgensen)
    > Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
    > Subject: Request specific singleton in webservice ?
    > Date: 28 May 2004 04:58:21 -0700
    > Organization: http://groups.google.com
    > Lines: 19
    > Message-ID: <>
    > NNTP-Posting-Host: 217.157.117.32
    > Content-Type: text/plain; charset=ISO-8859-1
    > Content-Transfer-Encoding: 8bit
    > X-Trace: posting.google.com 1085745501 1877 127.0.0.1 (28 May 2004

    11:58:21 GMT)
    > X-Complaints-To:
    > NNTP-Posting-Date: Fri, 28 May 2004 11:58:21 +0000 (UTC)
    > Path:

    cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!news-out.cwi
    x.com!newsfeed.cwix.com!prodigy.com!prodigy.com!news.glorb.com!postnews1.goo
    gle.com!not-for-mail
    > Xref: cpmsftngxa10.phx.gbl

    microsoft.public.dotnet.framework.aspnet.webservices:24047
    > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
    >
    > Hi,
    >
    > I would like to use the singleton pattern in a webservice in order to
    > ensure one and only one instance of certains objects within the
    > context of the webservice request.
    >
    > When I try to build the usual singleton pattern with the static
    > instance variable I notice that the static member is shared between
    > different webservice call which is NOT what I want.
    >
    > I am considering using the HttpContext.Current.Items dictonary as a
    > kind of webservice local singleton storage in order to avoid the
    > singletons being shared between webservice call, but it would require
    > a lot refactoring in the current application.
    >
    > Does anyone know a better way to obtain webservice locale singletons ?
    >
    > best regards
    > Poul Lund Jørgensen
    >
     
    Charlie Nilsson [MSFT], May 28, 2004
    #2
    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. Proton Projects - Moin

    Singleton - Whether Cloneable overrides Singleton

    Proton Projects - Moin, Mar 26, 2007, in forum: Java
    Replies:
    4
    Views:
    3,259
    Proton Projects - Moin
    Mar 27, 2007
  2. Wilhelm
    Replies:
    1
    Views:
    167
  3. Trans
    Replies:
    12
    Views:
    280
    Robert Klemme
    Sep 14, 2007
  4. Paul McMahon
    Replies:
    3
    Views:
    207
    David A. Black
    Jun 9, 2008
  5. Charles Oliver Nutter

    Singleton methods without the singleton class

    Charles Oliver Nutter, Mar 15, 2010, in forum: Ruby
    Replies:
    4
    Views:
    204
    Charles Oliver Nutter
    Mar 22, 2010
Loading...

Share This Page