CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2006
    Posts
    19

    Holding data in a WebService

    Hi Folks -

    I'm trying to use a Webservice as "interface" for a an oracle database.
    So my goal is, that all users on my website share the database connection
    and are always up to date by receiving data from this webservice.

    But this doesn't work at all, I'm not able to setup the proxy instances
    correctly it seems.. every visitor of my page receives its own instance of my webservice.. thatfor I created a little example webservice & application with just a button and a counter.
    My goal is, that the counter in my Webservice has the same value for each client!

    If for example client a increases the counter by clicking a button, client b should start with that increased value on visiting the asp application site.


    ---------------Code from the calling application----------------

    Protected Sub Increase_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim ret As Integer

    If Session("myCookie") Is Nothing Then
    Dim Cookies As New System.Net.CookieContainer
    Session("myCookie") = Cookies
    End If

    If Session("wsTest") Is Nothing Then
    Dim proxy As New wsTestPage.wsTestPage
    proxy.CookieContainer = Session("myCookie")
    Session("wsTest") = proxy
    End If

    ' Cookiecontainer für Proxy festlegen
    ret = Session("wsTest").TestWebService()
    Label1.Text = "Result: " & CStr(ret)

    End Sub


    ---------------Code from the WebService----------------

    <WebMethod(EnableSession:=True)> _
    Public Function TestWebService() As Integer
    If Context.Session("Counter") Is Nothing Then
    Context.Session("Counter") = 1
    Return (Context.Session("Counter"))
    Else
    Context.Session("Counter") += 1
    Return (Context.Session("Counter"))
    End If
    End Function


    Is it actually possible to do what I want with a WebService?
    If so, what am I doing wrong here?

    Thanks in Advance,
    Regards,

    Andy

  2. #2
    Join Date
    Jun 2003
    Location
    Fleet, Hampshire
    Posts
    144

    Re: Holding data in a WebService

    I'm not sure why you would want to do that?
    this would mean you would open the DB Once and Keep it open?
    why would you want to do that?
    Kind Regards,
    Gary
    www.threenineconsulting.com

    "A fool will learn nothing from a wiseman , but a wiseman will learn plenty from a fool"

  3. #3
    Join Date
    Oct 2006
    Posts
    4

    Re: Holding data in a WebService

    Hi Andy,
    Web service is a way of interacting and sharing data across heterogenious systems and it is a stateless protocol. In otherwords, caching a open connection in web service may not be recomended idea. Instead, you can close the connection and reopen it ,when ever need and leave everything else to .NET Framework connection pooling mechanism.
    Another unwanted situation of sharing same connection is transaction. Most of .NEt data providers , supports only one transaction per connection, so if you have more than one user trying to modify database content, then you can imagine what would happen
    Hope this is helpful..

    -thank you,
    bravey
    ASP.NET and C# Resources http://softlogger.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured