Integrating Static Content into a Web Service (Real-Time, Windows)

LabVIEW 2018 Help

Edition Date: March 2018
Part Number: 371361R-01
View Product Info

DOWNLOAD (Windows Only)

LabVIEW 2016 Help
LabVIEW 2017 Help
LabVIEW 2018 Help
LabVIEW 2019 Help
LabVIEW 2020 Help

Parent Topic: Components of a Web Service

Note Note  For more information about concepts in this topic, refer to the Web services introduction and tutorial. LabVIEW Web services are available only in the LabVIEW Full Development System and the LabVIEW Professional Development System.

When you build a Web service, you can integrate static content such as HTML files, stylesheets, images, and JavaScripts from within the LabVIEW project. For example, you can publish stand-alone web pages using Web services or provide a user interface that interacts with the HTTP method VIs in a Web service.

Note  Before you add static content to a Web service, organize static content on disk in two main folders: one that contains public content and, if necessary, one that contains private content you do not want to expose to users.

Complete the following steps to integrate static content into a Web service:

  1. Open the LabVIEW project that contains the Web service files.
  2. Right-click the Web service project item in the project tree and select Add Public Content Folder or Add Private Content Folder.
  3. In the browse dialog box that appears, select the folder on disk that contains files you want to include in the Web service.
  4. LabVIEW creates an auto-populating folder named Public Content or Private Content under the Web service project item. Any files in the folder on disk appear under the folder you added to the project tree.

    The following project shows a project that contains a Public Content folder. The corresponding folder on disk contains the same files and subfolder as in the project tree.

After you publish the Web service, you can access the static files from a client, such as a web browser, by navigating to the URL mapping for the file you want to access.

Finding the URL Mapping for a Public File

LabVIEW automatically assigns a URL mapping to each public static file. You cannot change this mapping. Complete one of the following steps to view the URL mapping for a public static file:

  • For a specific static file or folder, right-click the file in the project tree and select Show Public URL. If the Web service is not published, LabVIEW shows the URL for communicating with the file in a debugging session.
  • To view URL mappings for all public static files and folders, right-click the Web service project item and select Properties to display the Web Service Properties dialog box. On the Site Map page, the table contains a row with the URL mapping for each public static file and folder.

Integrating Default HTML Files

You can include an index.html file within each public content folder and subfolder in the project. When a client sends an HTTP request using a URL such as http://localhost/TutorialService/, the Web service returns the index.html file.

Complete the following steps to integrate a default index.html file for a specific public content folder:

  1. On disk, add a file named index.html to a folder that appears under the Public Content folder in the project. In the previous example, you place the file in the folder on disk that you associated with the top-level Public Content folder. The file automatically appears in the project tree unless you stop the folder from auto-populating changes in the corresponding folder on disk.
    Note Note  The file extension must be .html.
  2. Right-click the Web service project item and select Properties.
  3. On the Service Settings page, place a checkmark in the Serve default index.html for public folders checkbox, and click OK.
  4. In a Web browser, navigate to the URL that corresponds to the folder with the index.html file. The HTML file loads in the browser.

Integrating Private Content in Web Services

Private static files do not have URL mappings because web clients cannot access private content. To programmatically access private static content within Web service source files, use the Read Service Attribute VI to return the path to the folder that contains private content at run time. With the path to the private content folder, you can build a path to a specific file. Refer to the Read Service Attribute VI help for more information.

Related Information

Components of a Web Service: Static Files


Not Helpful