Note: The Call LabVIEW Web Service demo requires the included LabVIEW Web Service to be running locally on your machine.
This example demonstrates how to create a WebVI that makes requests to a LabVIEW web service, and how to create a LabVIEW web service that can respond to requests from a WebVI.
Use LabVIEW to create web services that do what WebVIs can’t do, such as:
CallLabVIEWWebService\CallLabVIEWWebService.lvprojectin LabVIEW NXG.
index.gviweband click the Run button.
Note: To view the build output on your machine, click Locate Directory in Windows Explorer on the Document tab once your application finishes building. You can automatically launch and view the Web application locally by going to System Designer » Web Server » right-click
WebApp.gcomp » Run
You can manually the move the build output found at
Builds to any web server. This project also includes a Distribution (
WebApp.lvdist) that can be used to build a package (.nipkg). Packages utilize NI Package Manager to automated the process of installing, upgrading, or removing the web app. A package is also a requirement for hosting a Web application on SystemLink Cloud.
The following steps can be used to host the web app on SystemLink Cloud
The following steps can be used to host the web app on a local web server
C:\Program Files (x86)\National Instruments\Shared\NI WebServer\www.
WebApp_Web Serverdirectory into the
C:\Program Files\National Instruments\Shared\Web Server\htdocs.
WebApp_Web Serverdirectory into the
Web Service— Contains the LabVIEW web service project.
WebVI— Contains the LabVIEW NXG web application project, which includes the WebVI.
The web service is created in LabVIEW and consists of two HTTP endpoint methods (one
GET and one
POST) and a few SubVIs.
You must configure the Output Type correctly in order for a LabVIEW web service to send data to a WebVI.
Write Response.vi. b. Option 2: Select Terminal and select JSON as the output format.
Cross-Origin Resource Sharing (CORS) allows a Web Service VI to respond to HTTP requests from a different server than where it is hosted.
AddCORSHeaders.vi adds HTTP headers to allow requests from any origin. This configuration is necessary if your WebVI is not hosted on the LabVIEW web server.
The WebVI makes requests to both of the HTTP endpoint methods in the LabVIEW web service and displays the returned data. For the POST method, it collects some parameter information from the panel controls and serializes it into the POST buffer.
This example show how to include your WebVI as part of your LabVIEW Web service for either Windows or Real-Time and deploy them together. This is advantageous if you want to avoid CORS between your WebVI and Web service in production. This also allows the use of relative URLs on the WebVI block diagram.
WebApp_Web Server directory has been included as Public Content within the LabVIEW project. This was done by right-clicking the Web service in the project and selecting Add Public Content Folder. In the Open dialog the
WebApp_Web Server directory was selected. This is an auto populating folder so changes made by modifying the WebVI and rebuilding the application in LabVIEW NXG are automatically up taken by LabVIEW project. See more details on this topic at Integrating Static Content into a Web Service.
In the WebVI there is a drop down for selecting the URL configuration.
http://127.0.0.1:8001/Web_Server/ParametricCurvein each HTTP request. Fully qualified URLs must be used if the Web service access by the WebVI is on a different host than the WebVI itself; e.g. CORS. The Web server here is the Local Debugging Web server built into LabVIEW. This is enabled by right-clicking the Web Service in the LabVIEW project and selecting Start.
ParametricCurvein each HTTP request. The rest of the URL is filled in automatically by the browser. This technique is useful because URLs in code don’t need to be changed as the hostname, protocol, or port or the Web service is changed. The Web service and WebVI are deployed to the Application Web Server by right-clicking the Web service in the LabVIEW project and selecting Publish.