This should be fairly basic, but say I have a Public property as local variable on my WCF service, and I set this in one call to the service. Is there a way to preserve that data for another call to the service? (Without writing the data to xml or a db, and re-referencing it or anything like that)
Executing the calls from the Winform:
Public Class ClientSideWinForm
Private proxy As ServiceReference.Client
Private Sub Client_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
proxy = New ServiceReference.Client
End Sub
Private Sub btnStartTests_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartTests.Click
addToTxtResults("Try Chk Program Valid...")
Try
addToTxtResults(proxy.RequestChkValidProgram("Some-serial-number")) 'returns true or false and instanciates the object server side
addToTxtResults(proxy.RequestFirstName()) ' returns nothing
Catch ex As Exception
addToTxtResults(ex.ToString)
End Try
End Sub
End Class
The service itself (dumbed down a bit, but the behaivor still exists):
Public Class Service
Implements IService
Public Property X As String
Function RequestChkValidProgram(ByVal strSerialNumber As String) As Integer Implements IService.RequestChkValidProgram
X = "hello"
End Function
Function RequestFirstName() As String Implements IService.RequestFirstName
Return X
End Function
End Class
If I understand the question correctly, your service implementation’s state is lost between service calls. You should look into setting the InstanceContextMode ServiceBehavior of your service implementation – it sounds like it’s currently set to
PerCall, such that every service call gets its own instance.PerSessionorSinglemay be better alternatives.And while I don’t necessarily agree with @John Saunders that this is a bad idea, it would be useful to have more details about what you’re trying to accomplish. 🙂