10-28-2008 03:24 PM
I need help with a problem concerning web services on 8.6. I am not even sure if this can be done.
I have a web service that works just fine. At this stage all it does set a boolean value.
For the test, I am just using IE to see the data. It works. I can see the boolean value change whenever I send a 0 or >1 value through the URL.
My problem is this: When I change the boolean value, I cannot read that value from another IE application. In other words, I want to be able to open two IE sessions in two different windows. When I change a value from one session of IE, I want to see the value change in the other session of IE(after refresh). As of now, it seems that every session of IE is a separate instance of the web service. How can I change a boolean value and read that change from a different IE session?
Is my cause hopeless? Are web services "read only" ? Any help would be appreciated.
Solved! Go to Solution.
10-28-2008 03:57 PM
Your cause is not hopeless. Web services are not read only.
To tell you what you are doing wrong I would have to see the VI in question.
When your web service is called from two separate browser sessions the same "instance" as you said of your VI will be executed. There are, however, a few things that might be good to remember-
1) If the VI is reentrant, which it should be unless you want your clients to be serialized, then you will be running a clone of your actual VI. This would produce the problems you are seeing.
2) If the VI's controls initialize to their default values on run then you would not preserve data from previous calls.
3) If you are always calling your service with the boolean parameter then of course it will always be overwritten with the new call. I assume you aren't doing this.
You need to incorporate a mechanism to save your state between executions of your VI, keeping in mind that it must be safe to access from multiple clients at the same time. The most straight-forward way to do this is to create a LabVIEW 2 style global. A non-reentrant VI with an uninitialized shift register that can be used to set and preserve your state from one call of your VI to the next. The non-reentrancy (is that a word) of the vi will force any web service VIs that try and access it to take turns.
Let me know how it goes or if you have questions about my convoluted response. 🙂
Nathan
10-30-2008 10:10 AM
Nathen,
Thanks for the quick response. I have tried several things but nothing works yet.
The VI I have is simply a boolean control connected to a boolean indicator.
In regards to your statements,
1. My VI is not reentrant. I tried making it reentrant, but it didn't help. I am confused because you said my VI SHOULD be reentrant, then you said it could cause problems, unless I am reading it wrong. If it does need to be reentrant, which option do I want??
2. I think my VI controls DO initialize to their default value on run. How can I make it NOT initialize to it's default value?
3. I am not calling my service with the boolean parameter. First I call the service with the parameter, then I use a different call with no parameters. Still, it seems as though when I call the VI with no parameters, the control is inputting it's default value to the indicator.
I created a global. I set a boolean with one VI, and read it with another VI, but it wouldn't work.
What is a LabVIEW 2 style global?
How can I call an unitialized VI and set a control then read it again without the VI "starting over"???
Thanks again,
Tony
10-30-2008 10:46 AM
Sorry for the confusion,
1- If the vi is not reentrant then you can't have more than one user connected at the same time. Each request for your service would have to take its turn. I would recommend making it reentrant- it makes more sense.
I think I may realize the problem. If you have a web service that takes a parameter and you leave the parameter off then the default value for that control will be used.
You should instead have a separate parameter that specifies whether you are getting or setting. Something like the attached VI.
10-30-2008 11:01 AM
This VI is a good example of a LabVIEW 2 style global. The value while loop's uninitialized shift register will persist from one call to the other of this VI. So when set is true the value of data is stored in the shift register. When set is false the value of the shift register is returned without changing it. Make sure that you have 'Keep VI in memory' checked in your web service configuration.
You could accomplish the same thing without the set parameter by using two separate VIs.
10-30-2008 11:01 AM
IT WORKS!!!!
Thanks so much for the help. I told my engineer it was worth upgrading to 8.6 because of the web service now I will not have bitten off more than I can chew.
10-31-2008 02:27 PM
10-31-2008 02:45 PM
The web services feature was introduced in LabVIEW 8.6.
In order to accomplish this same task before 8.6 you would have to either use the CGI abilities of the G-Webserver or code a web server using the TCP primitives.
I'm afraid there isn't much that we have discussed in this thread that would be applicable in versions of LabVIEW before 8.6.
Nathan
11-25-2013 05:46 AM - edited 11-25-2013 05:48 AM
Can someone give me an example of two separate VIs web service, one for set and other for get, using VI Server to share data ?
Thank.
11-26-2013 05:51 PM
you can try searching for an example at ni.com/examples