Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Web service instance

Web service instance

Scheduled Pinned Locked Moved C#
csharpwcf
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HahnTech
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • H HahnTech

      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

      L Offline
      L Offline
      Looney Tunezez
      wrote on last edited by
      #2

      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

      H 1 Reply Last reply
      0
      • L Looney Tunezez

        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

        H Offline
        H Offline
        HahnTech
        wrote on last edited by
        #3

        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

        A S 2 Replies Last reply
        0
        • H HahnTech

          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

          A Offline
          A Offline
          Allan Eagle
          wrote on last edited by
          #4

          Can you post the code for the web service class? Maybe something is wrong in there?

          1 Reply Last reply
          0
          • H HahnTech

            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

            S Offline
            S Offline
            S Senthil Kumar
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups