Web service instance
-
I’m writing a distributed app. I have a web service and windows form. In my form I have declared an instance of the web service like so: WindowsForm.localhost.service1 ws = new WindowsForm.localhost.service1(); The web service has a web method that sets a string and another web method that retrieves it. The string (m_word) is initialized to “ “ (space). This is what I’m trying: Some button event handler () { ws.SetString(this.textbox.text); } Other button event handler() { this.Lable1.text = ws.GetString(); } What I’m expecting to happen it the word from the text box will appear in the lable but it doesn’t. Its as if I’m typing this. Some event handler() { WindowsForm.localhost.service1 wsA = new WindowsForm.localhost.service1(); WsA. SetString(this.textbox.text); } Some other event handler() { WindowsForm.localhost.service1 wsB = new WindowsForm.localhost.service1(); this.Lable1.text = wsB.GetString(); } I know this is a bit cryptic so if any one need clarification let me know. I think I’m missing something about how web services’ live. Ronald Hahn, CNT - Computer Engineering Technologist New Technologies Analyst HahnTech Affiliated With Code Constructors Edmonton, Alberta, Canada Email: rhahn82@telus.net
-
I’m writing a distributed app. I have a web service and windows form. In my form I have declared an instance of the web service like so: WindowsForm.localhost.service1 ws = new WindowsForm.localhost.service1(); The web service has a web method that sets a string and another web method that retrieves it. The string (m_word) is initialized to “ “ (space). This is what I’m trying: Some button event handler () { ws.SetString(this.textbox.text); } Other button event handler() { this.Lable1.text = ws.GetString(); } What I’m expecting to happen it the word from the text box will appear in the lable but it doesn’t. Its as if I’m typing this. Some event handler() { WindowsForm.localhost.service1 wsA = new WindowsForm.localhost.service1(); WsA. SetString(this.textbox.text); } Some other event handler() { WindowsForm.localhost.service1 wsB = new WindowsForm.localhost.service1(); this.Lable1.text = wsB.GetString(); } I know this is a bit cryptic so if any one need clarification let me know. I think I’m missing something about how web services’ live. Ronald Hahn, CNT - Computer Engineering Technologist New Technologies Analyst HahnTech Affiliated With Code Constructors Edmonton, Alberta, Canada Email: rhahn82@telus.net
My understanding of your problem is this: in the first event, you are creating a webservice object wsA, whose string variable you set to a particular value. But then when you call the function GetString() its on an entirely new object of the webservice class.So technically you should get " " back as the result. You need to use the same instance of the class to persist the value. So instead of creating a new object of webservice class, call the GetString() on wsA instead of wsB. HTH Cheers! Looney Tunezez "If you build it.... .....BUGS will come!" -JB
Application.Run(new Form1(this.Dispose())); <--WHAT :wtf::confused::eek:
"Stability. What an interesting concept" - Chris Maunder -
My understanding of your problem is this: in the first event, you are creating a webservice object wsA, whose string variable you set to a particular value. But then when you call the function GetString() its on an entirely new object of the webservice class.So technically you should get " " back as the result. You need to use the same instance of the class to persist the value. So instead of creating a new object of webservice class, call the GetString() on wsA instead of wsB. HTH Cheers! Looney Tunezez "If you build it.... .....BUGS will come!" -JB
Application.Run(new Form1(this.Dispose())); <--WHAT :wtf::confused::eek:
"Stability. What an interesting concept" - Chris MaunderYeah I got all that. In the first part of my question I said that I have a global Web service declared and I’m using it in my functions but when I use it from two function calls It looks like I’m getting two different instances of the web service. Ronald Hahn, CNT - Computer Engineering Technologist New Technologies Analyst HahnTech Affiliated With Code Constructors Edmonton, Alberta, Canada Email: rhahn82@telus.net
-
Yeah I got all that. In the first part of my question I said that I have a global Web service declared and I’m using it in my functions but when I use it from two function calls It looks like I’m getting two different instances of the web service. Ronald Hahn, CNT - Computer Engineering Technologist New Technologies Analyst HahnTech Affiliated With Code Constructors Edmonton, Alberta, Canada Email: rhahn82@telus.net
Can you post the code for the web service class? Maybe something is wrong in there?
-
Yeah I got all that. In the first part of my question I said that I have a global Web service declared and I’m using it in my functions but when I use it from two function calls It looks like I’m getting two different instances of the web service. Ronald Hahn, CNT - Computer Engineering Technologist New Technologies Analyst HahnTech Affiliated With Code Constructors Edmonton, Alberta, Canada Email: rhahn82@telus.net
Hi, Web services are stateless, they don't preserve information across method calls. If you want to preserve state, you need to implement your own mechanism, like passing around a session key.. Regards Senthil