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\WebService\WebService.lvproj
in LabVIEW.CallLabVIEWWebService\CallLabVIEWWebService.gwebproject
in G Web Development Software.index.gviweb
and click the Run button.WebApp.gcomp
.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
CallLabVIEWWebService\CallLabVIEWWebService.gwebproject
.WebApp.lvdist
.The following steps can be used to host the web app on a local web server
CallLabVIEWWebService.gwebproject
WebApp.lvdist
.http://localhost:9090/calllvwebservice/
C:\Program Files (x86)\National Instruments\Shared\NI WebServer\www
.WebApp_Default Web Server
directory into the www
directory.http://localhost:8080/WebApp_Default%20Web%20Server/
C:\Program Files\National Instruments\Shared\Web Server\htdocs
.WebApp_Default Web Server
directory into the htdocs
directory.http://localhost:9090/WebApp_Default%20Web%20Server/
.Web Service
— Contains the LabVIEW web service project.WebVI
— Contains the G Web Development Software web application project, which includes the WebVI.WebVI/Builds/WebApp_Default Web Server
— Contains the built web application, which consists of HTML, JavaScript, the compiled diagram, and other web content.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.
The WebApp_Default 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_Default Web Server
directory was selected. This is an auto populating folder so changes made by modifying the WebVI and rebuilding the application in G Web Development Software 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/ParametricCurve
in 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.ParametricCurve
in 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.