Lost session in webservice
I use a webservice project and add refference it to presentation project.
In webservice, I use session to store a value. Howerver, it cannot be keeped.
Please open my sollution and help me ASAP.
Thanks
Webservice Code
Code:
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Service1
Inherits System.Web.Services.WebService
<WebMethod(True)> _
Public Function HelloWorld() As String
Setsession("Thank You")
Return ""
End Function
<WebMethod(True)> _
Public Function getses() As String
Return GetSession()
End Function
Private Sub Setsession(ByVal value As String)
Session.Add("a", value)
End Sub
Private Function GetSession() As String
Return Session("a").ToString
End Function
End Class
Presentation Code
Code:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As New localhost.Service1
Dim s As String = a.HelloWorld
Response.Write(a.getses())
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim a As New localhost.Service1
Response.Write(a.getses())
End Sub
End Class
Re: Lost session in webservice
Remember that I use webservice as a separate project. If i use webservice in presentation project, the session is keeped!
Re: Lost session in webservice
Do not use a session in a web service. A web service is not a web application which works on a user-session. However, it is still possible, though I call it bad design.
http://msdn2.microsoft.com/en-us/library/aa480509.aspx
I hope this article helps.
Re: Lost session in webservice
Thank you. That link show what I ask but its solution cannot solve the problem.
The session is still lost.
Re: Lost session in webservice
Perhaps, explain what your goal is, then.
Re: Lost session in webservice
I want to keep the session varriable at webservrice everytime I call the function at webservice. I need to keep it as a temerary database memory. Each action will update value to it and get value from it.
Re: Lost session in webservice
Hmm. So let's see... you don't want to use your own application to store session variables. Instead, you're perfectly content with sending the session variables out over the wire, thereby increasing the security risk to your application by exposing user-specific data to 'the world', and then using another ASP.NET application/web service to act as a holder for this. You'll pardon me for being cynical, but I am pedantic and point out bad practices when I see it.
That said, you said that you want to keep it in a database. In that case, you would like to use ASP.NET session management, using SQL Server.
Have a look at the first few articles here. You really don't need a web service to do this.