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

Parent Topic: Developing Web Services

When you build a Web service, you can integrate static content such as HTML files, JavaScript files, CSS files, images, and videos 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  If you want to integrate LabVIEW NXG WebVIs with a LabVIEW Web service, include the built WebVI files in the Public Content folder in your LabVIEW Web service project. Refer to Using WebVIs to Create User Interfaces for Web Services for more information.

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

  1. Organize static content on disk in two main folders: one that contains public content and one that contains private content you do not want to expose to users.
  2. Open the LabVIEW project that contains the Web service files.
  3. Right-click the Web service project item in the project tree and select Add Public Content Folder or Add Private Content Folder.
  4. In the browse dialog box that appears, select the folder on disk that contains files you want to include in the Web service.
  5. 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 that 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:

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