locked
Keep object alive on server in a WCF Service RRS feed

  • Question

  • Hello all,

                I need to keep an object alive on the server. It's a data context from a connection to a server.

    How could I achieve this in WCF please ...

    Thanx a lot !

    Friday, November 19, 2010 3:57 PM

Answers

  • Hi,

    Please be more specific.

    What should determine the lifetime of that object?

    How is this relevant to WCF services (and especially WCF Data Services which is the topic of this thread)?

    Thanks,


    Vitek Karas [MSFT]
    Friday, November 19, 2010 5:12 PM
    Moderator
  • Thanx for your reply,

                                   The WCF Service opens a connection to an external server. I want this connection (datacontext) to be alive because the client can calls the method hundreds of time. In Asp.Net i would use the application scope var, what would be the best practice for a WCF service ?

    Thanx a lot

    Friday, November 19, 2010 6:06 PM
  • There is no in thebox support for this kind of scenario. Since WCF data service is stateless on the server, you will need to use some encrypted cookie or do it based on authentication. Override the CreateDataSource method on your service class, and use the same connection string or same data source instance for the same cookie or same user.

    Hope this helps.

    Thanks

    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Friday, November 19, 2010 7:36 PM
    Moderator

All replies

  • Hi,

    Please be more specific.

    What should determine the lifetime of that object?

    How is this relevant to WCF services (and especially WCF Data Services which is the topic of this thread)?

    Thanks,


    Vitek Karas [MSFT]
    Friday, November 19, 2010 5:12 PM
    Moderator
  • Thanx for your reply,

                                   The WCF Service opens a connection to an external server. I want this connection (datacontext) to be alive because the client can calls the method hundreds of time. In Asp.Net i would use the application scope var, what would be the best practice for a WCF service ?

    Thanx a lot

    Friday, November 19, 2010 6:06 PM
  • There is no in thebox support for this kind of scenario. Since WCF data service is stateless on the server, you will need to use some encrypted cookie or do it based on authentication. Override the CreateDataSource method on your service class, and use the same connection string or same data source instance for the same cookie or same user.

    Hope this helps.

    Thanks

    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Friday, November 19, 2010 7:36 PM
    Moderator