NeilA Posted October 16, 2008 Report Share Posted October 16, 2008 I have a need to have an executive program which will be fed by a web service. For example I will have a remote computer running a sequencer that calls for example an execute method on my machine that will start a test on RF equipment based on a test number. Now my first problem is that my company is already getting some one to develop a SOAP to Restful service converter so that the services can be called in my program. I have read and read through info on the net and tried examples etc and cant work this out. What I cant fathom in my stupidity is how do you get the VI to run within my executive VI. From what I can tell from what I have played with so far, the VI doesn't seem to execute it just executes the method called and gives you the output vi HTML in the web client you make the request from. I need the outputs to be passed on to the later items in my executiv VI. The idea of using web methods is so that the system is effectively idling while no messages are sent so I don't want to be pollonig outputs of a VI etc. like using event structures instead of timed while loops. I may be being totally silly but I cant figure this out. I am having to figure out lots of things I don't know anything about in my new job and I think I have stewed my brain. Many thanks in advance. Neil. Link to comment
ned Posted October 16, 2008 Report Share Posted October 16, 2008 QUOTE (NeilA @ Oct 15 2008, 11:42 AM) I have a need to have an executive program which will be fed by a web service. For example I will have a remote computer running a sequencer that calls for example an execute method on my machine that will start a test on RF equipment based on a test number. Now my first problem is that my company is already getting some one to develop a SOAP to Restful service converter so that the services can be called in my program.I have read and read through info on the net and tried examples etc and cant work this out. What I cant fathom in my stupidity is how do you get the VI to run within my executive VI. From what I can tell from what I have played with so far, the VI doesn't seem to execute it just executes the method called and gives you the output vi HTML in the web client you make the request from. I need the outputs to be passed on to the later items in my executiv VI. The idea of using web methods is so that the system is effectively idling while no messages are sent so I don't want to be pollonig outputs of a VI etc. like using event structures instead of timed while loops. I may be being totally silly but I cant figure this out. I am having to figure out lots of things I don't know anything about in my new job and I think I have stewed my brain. Many thanks in advance. Neil. Hi Neil - NI doesn't make this as clear as they could in their documentation, but a web service VI executes independently of other VIs. For example, if you build a web service into an executable, you'll have one VI that runs as your application (in your case, the "executive") and another web method VI, and even though they're part of the same application they run separately. You'll need to implement the communication mechanism between the two of them yourself, using shared variables, VI server, shared files, etc. I don't understand exactly what you meant by "the VI doesn't seem to execute it just executes the method called" but if you provide a more detailed explanation or screenshots of your code, someone here can probably help you determine the best way to set this up. Link to comment
NeilA Posted October 16, 2008 Author Report Share Posted October 16, 2008 I think you cleared it up really, by backing up what I had thought. I meant that the method called does not directly "run" the VI (like clicking the run button) so there are no changes to a specific instance of a VI output. If I was to place the "Webservice VI" on the block diagram of another VI even if the web service VI is executed before the outputs are needed they will not have changed. By calling the webservice I only call a version of the method in reply to the html call. I think that is right? I am really new to this level of labview programming. I am an elec/RF eng based on training and experience but got my current job because of my LabVIEW basics training and RF experience. I only have basics 1 and 2 and that was back in the days of version 7. Another quick question then, of the examples you gave for variables etc which would be best to use in an event driven system like a QSM or AE. I need to build this based on a slick GUI for local use to automate testing but with probably 50% remote use also. So I thought that the base of a QSM-PC form would be best so that I can have a few parallel queues for test data, status of testing etc. So it is important to pick an adequate variable type. As you may be able to tell I am on a very sharp learning curve at the moment. I realise I am asking akward questions when you dont really have much of a clue what I am doing so thanks in again for any help!! Neil. Link to comment
ned Posted October 16, 2008 Report Share Posted October 16, 2008 QUOTE (NeilA @ Oct 15 2008, 12:44 PM) Another quick question then, of the examples you gave for variables etc which would be best to use in an event driven system like a QSM or AE.I need to build this based on a slick GUI for local use to automate testing but with probably 50% remote use also. So I thought that the base of a QSM-PC form would be best so that I can have a few parallel queues for test data, status of testing etc. So it is important to pick an adequate variable type. As you may be able to tell I am on a very sharp learning curve at the moment. I realise I am asking akward questions when you dont really have much of a clue what I am doing so thanks in again for any help!! Neil. Without a lot of information about what you're doing, here's my suggestion: use your queue-based system, and allow the web service to insert items into your queue. You can do this by creating a VI that executes in the same instance as your test executive that simply obtains a reference to the queue (named queues make this easier), places an item into it, and then releases the queue reference. Enable VI server and allow access to that VI. In your web method, open a reference to that VI through VI server and run that VI by reference, passing it whatever values need to be inserted into the queue. You may have to experiment with VI server for a while to get this to work - I suggest enabling TCP/IP specifically for your project (right-click on My Computer in the project explorer) and assigning it a unique port. Link to comment
NeilA Posted October 18, 2008 Author Report Share Posted October 18, 2008 Hi, Thankyou very much for your help. I have researched and implemented the VI server suggestions you made and they work to a degree. My problem is if the QSM (main prog) is running and I run the web service VI (this now includes the VI Server ref to the VI that adds to the queue in the main prog) directly from the run button I have an addition to the queue and a dummy test is triggered. If I invoke the web service method from a browser it doesnt invoke a test. I have the inputs to the webservice VI indicated on the connetor pane so that when I invoke the method from a browser the returned values show up in the browser in XML. However the values are not correct. I Send a message ie Execute and a test no. ie 1 (we call it MTI) I have the url mappings set to /:message/:MTI and if send http://localhost/RMSClient/Execute/1 I get this returned: - <Response>- <Terminal> <Name>MTI 2</Name> <Value>0</Value> </Terminal>- <Terminal> <Name>Message 2</Name> <Value>execute</Value> </Terminal></Response> I dont think the webservice is running the VI behind it properly. If I click the run button on my webservice VI without the main prog running I get an error based on the queue not being available and VI server getting an error because of this. But, if I do the same from via a browser call to the webservice VI NO Error! this leads me to believe that the VI may not be running properly. Are there any issues that I may not have realised that are glaringly obvious to those in the know? Once again thanks for the help! Neil. Link to comment
ned Posted October 18, 2008 Report Share Posted October 18, 2008 I set up a quick test project to make sure this works, and ran into some difficulties using VI server through ActiveX due to what seemed to be problems with application instances or my inability to determine the correct "full delimited name of the VI". The VI would run properly through VI Server but not in the same application instance as the test executive, so it would create its own new queue rather than using the existing one. Here's what I had to do. Set up VI server through TCP/IP. In the project explorer, right click my computer -> properties and select the VI server options (note that this is a project-specific setting). Enable TCP/IP on some non-standard port (the LabVIEW default is 3363, so try perhaps 13363). Then make sure your local machine is allowed to access the necessary VI. In your web method VI, open your application reference to that port on "localhost" (the local machine) so that it will use TCP/IP, not ActiveX. Finally, open the VI reference by name (the simple VI name is sufficient). This should get you a reference to the VI, in the correct application instance, so that it will get a reference to the correct queue. As you have probably already have figured out, you can add a string output terminal to your web method that contains the error status message; that way if the web method does generate an error you'll be able to see it easily. I found this to be very helpful in debugging a web method. Link to comment
NeilA Posted October 18, 2008 Author Report Share Posted October 18, 2008 Thanks for your help here but I think I may have misled you with my last post. I do not get an error in my web method it just does not appear to run the vi within the web service correctly. I have attached my webservice VI Block diagram (simple and messy - trying to prove a concept atm) this runs fine when from the run button and when my executive app is running it adds a test to the queue perfectly. My problem is that when I use internet explorer and call the vi as a web service using the prviously posted url mapping it doesnt do the same as when I press the run button. It also doesnt throw up an error when my exec prog isn't running. Both of these things are different to normal running of the VI from the run button, therefore I think this may be important since I would imagine both of these things to work the same just implemented differently. I have tried adding the Open Application Ref VI (I don't know if this is needed since it runs fine as is) but cant make this way work at all. If I have missed something here (easily done as this is new territory) and this is neccesary could you please post how I should be applying the address to the VI. I have enable the port I used 13363 like you said. Thanks again, Neil. Link to comment
NathanK Posted October 18, 2008 Report Share Posted October 18, 2008 ned, Connecting to the local main application instance using the method you described will work but in this case the VI server client is connecting as if it were a remote client. This has two repercussions- 1- you have to enable the vi server access and specify a unique port as you described, 2- You don't have access to some VI server functionality remotely. This is not so much of an issue if you are just running a VI. I'm sure you already know much of this but another way that you could go about getting the reference to your VI is with the following method: I had a VI that fired a dynamic event in my main application and I want it to be called from a web service. My main application happened to be in a project and I knew that project was the only project open. Alternatively you could use the property to get the main application instance (the property I don't have wired). Or if you didn't know what application instance your VI was in you could append them all to one array and search through them. Note that the VI is referred to only by name and not the full path. If you use a path then VI server will load the VI- with just the name the VI has to be in memory already- which is what I wanted. I hope that is helpful. Nathan Link to comment
ned Posted October 18, 2008 Report Share Posted October 18, 2008 Nathan - thanks, that's very helpful. I see now that I did not completely understand application instances, and so in order to get access to the one I wanted I just assigned it its own VI server port. I didn't realize that each application instance has its own application reference, and that "Open VI reference" connects to the main instance by default. Neil - here's the code that my quick test uses. I, like Nathan, used a call by reference node, which I think is preferable to your Invoke node. Link to comment
NeilA Posted October 18, 2008 Author Report Share Posted October 18, 2008 I am very appreciative of the help you guys are giving me, I am by no means super skilled in the art of G, but, I am learning fast. I am completely vexxed by the problem I have. In the simple VI that I have generated and shown in the previous posts and above when directly run via the run button a message is sent to the queue in the test executive VI (seperate so I am assuming the VI server code although not robust enough to use in a proper app is doing what it should and calling the queue app). The VI server function is calling a queue VI below: The VI below is a dummy test executive to prove the concept. If I press the run button on the webservice VI it all works. The test vi in the test exec is called and it appears to work as it should. If i call the webservice VI via the webservice I created in the build specifications in the project manager i get the text back as I posted in a previous post - <Response> - <Terminal> <Name>Message 2</Name> <Value>execute</Value> </Terminal> <Terminal> <Name>MTI 2</Name> <Value>0</Value> </Terminal> <Terminal> <Name>Error</Name> <Value>No Error</Value> </Terminal> </Response> But the test.vi in the Test executive is not called. This leads me to beleive that some part of the webservice VI is not functioning correctly when called by the URL. The problem is the only feedback I get back from the webservice is the xml formatted text in the browser. I am very greatful for all your help. I have a mac at home and no LabVIEW so have posted what code I could before I leave work. I will keep an eye on this thread over the weekend as it has got me very intreagued as to what I am doing wrong. Any code related examples needed will have to wait until monday morning. Many Thanks and have a nice weekend!!! Neil. Thanks Nathan and ned! It took me so long to get my screen grabs and write the text you replied before I finished. It is six o'clock here in UK and late to be at work on a Friday. I have given it a brief look and I am very happy that what I have posted in most aspects its similar to what you have posted. I dont have time to implement the changes now but will do on Monday. Can you confirm that when you call the webservice via a URL in a browser that it runs the enque VI and an element gets added to the queue in the main test executive? I would like to confirm that I am getting my webservice correctly set up in build specifications. I imagine your url mapping is something like /enqueue/:Action with a URL test of http://localhost/enqueue/1. I have my HTTP method as GET is that correct? As I said in my last post have a great weekend! And thanks for the help. Neil. Link to comment
Norm Kirchner Posted October 18, 2008 Report Share Posted October 18, 2008 I would like to propose an alternative to the solutions provided thus far. LVx and Exported Functions This is a design pattern that allows you to have a program running (a LV exe for example ) and have it easily respond to command requests from practially any LV source (another LV EXE, dev system on same PC, a PC in a lab around the world) and return the appropriate data packaged up w/ it. This method gives the exact functionality that you are looking for minus the web-services part. The beauty is that it uses some of the exact concepts presented so far but in a much cleaner fashion and much more extensible. Please do not be put off by the use of LVOOP as this is a great place to get your feet wet with it even if you're a beginner. I'm sure there are more details that need to be given, but check out the linked thread and ask away. Link to comment
ned Posted October 21, 2008 Report Share Posted October 21, 2008 QUOTE (NeilA @ Oct 17 2008, 01:11 PM) I dont have time to implement the changes now but will do on Monday. Can you confirm that when you call the webservice via a URL in a browser that it runs the enque VI and an element gets added to the queue in the main test executive?I would like to confirm that I am getting my webservice correctly set up in build specifications. I imagine your url mapping is something like /enqueue/:Action with a URL test of http://localhost/enqueue/1. I have my HTTP method as GET is that correct? Hi Neil - yup, that's how I have the URL mapping set. If you don't get it working on Monday morning I can post my demo project here when I get into the office (which will probably be near the end of the day for you in UK). Link to comment
NeilA Posted October 21, 2008 Author Report Share Posted October 21, 2008 Norm - Thanks for the help but the over all system requirements were not decided by me and I am having to follow a plan that was decided a while back and there is not much scope for change as the system I am working on is part of a larger system that has had a lot of work and developement already ie way too far down the line already. For all the benefits of using LabVIEW to work with the equipment and measured data. Having to use web services and XML for data and control is proving to be quite convoluted and definately no where near as simple as I would have hoped. Ned - Thanks for that I am working on changing my programs this morning if I get a chance and will get back to you later if I could do with some additional help. Lots of thanks to all! Link to comment
NeilA Posted October 21, 2008 Author Report Share Posted October 21, 2008 I have had some trouble getting this to work. I have made the changes to my code to get it using the same VI Server functions. The problem is if I run the VI I get an error 63 from Open Application Reference VI. Is it totally necessary to have the open application function in the program? Is this due to the firewall on my machine? Unfortunately I have no control over my firewall settings its a corporate IM Support thing. I have made other little web service VI's that work, like the example add program etc. These use localhost but dont specify a port number or anything. Could I be doing something else wrong now? Thanks for your help. Neil. Link to comment
ned Posted October 21, 2008 Report Share Posted October 21, 2008 QUOTE (NeilA @ Oct 20 2008, 11:39 AM) I have had some trouble getting this to work. I have made the changes to my code to get it using the same VI Server functions. The problem is if I run the VI I get an error 63 from Open Application Reference VI. Is it totally necessary to have the open application function in the program? Is this due to the firewall on my machine? Unfortunately I have no control over my firewall settings its a corporate IM Support thing. I have made other little web service VI's that work, like the example add program etc. These use localhost but dont specify a port number or anything. Could I be doing something else wrong now? Thanks for your help. Neil. If you use the approach that Nathan suggested you can avoid the Open App Reference. Your problem here might be due to your corporate firewall (although if it's just communication from the local machine to itself I can't see why the firewall would block it). Before assuming it's the firewall, make sure you've allowed access through TCP - right click "My Computer" in the project explorer, select "VI Server: Machine Access", enter "localhost" in "Machine name/address", select "Allow Access" and click add. You can also enter "*" as the machine name to allow access from any computer. Similarly, under "VI Server: Exported VIs" make sure that the VI you want to run through VI server is accessible. A quick explanation here about Application Instances, and the difference between using TCP (as I did it) or ActiveX (as Nathan suggests). Each LabVIEW project executes independently of any other projects that might be running on the same machine - each project has its own instance. There is also a main LabVIEW instance, for VIs that don't belong to a project. Web Method VIs appear to execute in a their own instance as well. Queues and other reference data types are not shared between application instances, which is why your web method can't communicate directly with your main application just by opening a queue with the same name as the one used by your test executive. Instead, you obtain a reference to that specific application instance, and run a VI inside of it, permitting it to share data. By default, Open Application Reference connects you to the main application instance. There are a few ways to get access to a specific application instance. One is the way I did it, by assigning it a unique TCP/IP port and then using Open Application Reference on that port. Another is the way Nathan did it, getting an array of all the available instances and then selecting the one you want. In Nathan's approach you already have the Application reference, so there's no need to open it - you can pass that application reference directly to Open VI Reference. Link to comment
NeilA Posted October 21, 2008 Author Report Share Posted October 21, 2008 OK I have added the options to the machine access and exported VI sections of the VI Server properties in My Computer. I didn't know those things existed hence why I missed it from your original post. I now get a proper error in the VI this is due to the fact that I was correct that my VI was not executing the case structure I have built is case sensitive but case defaults to lower when entered in the url bar of the browser. Now I have it selecting and running the case I get this error: - - <Response>- <Terminal> <Name>MTI out</Name> <Value>1.000000</Value> </Terminal>- <Terminal> <Name>Error</Name> <Value>Open VI Reference in RMS Webservice4.vi->RMS Webservice4.vi.ProxyCaller<APPEND> To load a VI into memory with the Open VI Reference function, a path must be wired for the VI Path input. VI Name: <b>Queue Item.vi</b></Value> </Terminal> </Response> I feel I am getting closer, the error asks for a full path however in the activeX version nathan suggests not to use full path and your image of your vi does not use the full path. Let me know if you need more info. I have to leave work now, thanks again. Neil. Link to comment
ned Posted October 21, 2008 Report Share Posted October 21, 2008 QUOTE (NeilA @ Oct 20 2008, 01:36 PM) - <Response> <Terminal> <Name>MTI out</Name> <Value>1.000000</Value> </Terminal> <Terminal> <Name>Error</Name> <Value>Open VI Reference in RMS Webservice4.vi->RMS Webservice4.vi.ProxyCaller<APPEND> To load a VI into memory with the Open VI Reference function, a path must be wired for the VI Path input. VI Name: <b>Queue Item.vi</b></Value> </Terminal> </Response> I feel I am getting closer, the error asks for a full path however in the activeX version nathan suggests not to use full path and your image of your vi does not use the full path. My guess, based on that error, is that you're almost there. In Open VI Reference, if you don't specify a path to the VI, you need to have the VI you want to call already loaded into memory (as per the documentation). Just double-click it in the project explorer so the front panel is open, and then try the web service again. A better long-term solution is to place a Static VI Reference to Queue Item.vi on the block diagram of the the test executive so that you can be certain that anytime the test executive is running, Queue Item.vi will be loaded into memory and available through VI Server. Link to comment
NeilA Posted October 22, 2008 Author Report Share Posted October 22, 2008 Hi, I have managed to get it working. Ned your suggestion got me passed the open application reference issue but I then had an error from the open VI reference. For some strange reason that I can't work out it didn't like specifc naming of the VI's to work only if I used an '*' it finally worked. I am extremely happy something has gone right for me today as my motorbike was stolen over night. I must thank all those of you who helped specially NedK. I now have a Restful web service triggering a queue in the main program, perfect! Link to comment
maxgod145 Posted February 13, 2009 Report Share Posted February 13, 2009 Hi Want to ask! How I can redact the xml or html created after build and deploy web service (restful)! if i use GET method the result show like table with answer!I want to change this answer or build it to another appliction!!????? Link to comment
John Lokanis Posted February 19, 2009 Report Share Posted February 19, 2009 Not sure if this will help but you can check out my web service project here. Some of the code show how to call into other LV apps from a web service and how to call a web service from within LV. One thing I wonder about is how to enumberate all the LV EXEs running on a target. I don't think the method of finding all open projects would work in that case since these are separate compiled EXEs. Anyway, here is the link: Screenshot Web Service Link to comment
John Lokanis Posted March 27, 2009 Report Share Posted March 27, 2009 QUOTE (NathanK @ Oct 17 2008, 09:00 AM) My main application happened to be in a project and I knew that project was the only project open. Alternatively you could use the property to get the main application instance (the property I don't have wired). Or if you didn't know what application instance your VI was in you could append them all to one array and search through them. I have a question about this. What if you want to write some code that will work in both the case of running under the dev env where you ahve a project open AND running as a compiled EXE, were the main exe is in the main app (default) instance. Can you test for DEV vs RTE in the web service? Does it even run as if it were in the DEV env? Is there a better was to detect this? thanks, -John Link to comment
gmart Posted March 27, 2009 Report Share Posted March 27, 2009 QUOTE (jlokanis @ Mar 26 2009, 02:07 PM) I have a question about this. What if you want to write some code that will work in both the case of running under the dev env where you ahve a project open AND running as a compiled EXE, were the main exe is in the main app (default) instance. Can you test for DEV vs RTE in the web service? Does it even run as if it were in the DEV env? Is there a better was to detect this?thanks, -John You could try using the App.Kind VI server property. Link to comment
John Lokanis Posted March 27, 2009 Report Share Posted March 27, 2009 QUOTE (gmart @ Mar 26 2009, 01:46 PM) You could try using the App.Kind VI server property. Yes, but what 'App.Kind' is a web service? Link to comment
gmart Posted March 27, 2009 Report Share Posted March 27, 2009 QUOTE (jlokanis @ Mar 26 2009, 04:52 PM) Yes, but what 'App.Kind' is a web service? App.kind returns what type of application is running the VI. So in the development environment, the property will return "Dev system" (or whatever it is). If a VI is loaded via the run-time engine, the property should return "Run Time System". Link to comment
John Lokanis Posted April 4, 2009 Report Share Posted April 4, 2009 QUOTE (gmart @ Mar 26 2009, 03:20 PM) App.kind returns what type of application is running the VI. So in the development environment, the property will return "Dev system" (or whatever it is). If a VI is loaded via the run-time engine, the property should return "Run Time System". Yes, but as it turns out this is not working correctly for web services. Here is the response I got from NI: "I just tested this, and the App.Kind property currently reports as being in the Development Environment. I don't believe this is proper behavior, so I reported it to R&D under Corrective Action Request (CAR#) 157042 so they might change it in a future version." Link to comment
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now