Click to See Complete Forum and Search --> : Holding data in a WebService


AndyTheAce
October 11th, 2006, 03:40 AM
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

cykophysh
October 11th, 2006, 11:44 AM
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?

bravey9
October 13th, 2006, 11:09 PM
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