Parent Topic: LabVIEW Web Services
Complete the following steps to build, deploy, and exchange data between a LabVIEW Web service and a Web client.
Note This topic assumes familiarity with the Web services introduction. LabVIEW Web services are available only in the LabVIEW Full Development System and the LabVIEW Professional Development System.
This tutorial contains the following sections:
- Creating a LabVIEW Application to Deploy as a Web Service
- Configuring the LabVIEW Application Web Server
- Creating a Web Service Project and Build Specification
- Deploying a Web Service to the Web Server
- Accessing a Web Service
Creating a LabVIEW Application to Deploy as a Web Service
Web method VIs use front-panel controls and the connector pane to exchange data via Web services. Use VIs on the Web Services palette to further customize how a Web method VI receives and sends data. Complete the following steps to create VIs for a Web services application.
- Create a new Web method VI to exchange data with Web clients over the network. You can include nearly all of the available functionality of LabVIEW that uses supported data types. The following figure displays an example front panel, block diagram, and connector pane of a Web method VI named add.vi that accepts two values from a Web client and returns the sum of those values to the client. You can build and use add.vi for the remainder of the tutorial. Steps labeled as optional in the tutorial are not required to build and deploy add.vi as a Web service application.
- Set up the controls, indicators, and the connector pane of the Web method VI for use in Web services. Any controls and indicators that exchange data over the network with a Web client must appear in the VI's connector pane.
- Create controls and indicators for any data that you want to communicate using Web services. For example, a VI that accepts two values from a Web client and returns the sum of those values to the client must have two controls and one indicator in the connector pane.
- Assign recognizable names to each object. These names become part of the URL that Web clients use to exchange data with the VI.
- Assign the controls and indicators to the connector pane. Any control and indicator that sends or receives data must appear on the connector pane when using Web services.
Note (Optional) You can add VIs from the Web Services palette to a Web method VI to enable more advanced Web-specific functions such as HTTP sessions, authentication, HTTP headers, and cookies. If you include VIs from the Web Services palette within a Web method VI, you must assign the httpRequestID control to the connector pane of the Web method VI.
- Save the VI. Use the name add.vi if you want to match the figures and textual examples throughout the remainder of the tutorial.
Configuring the LabVIEW Application Web Server
- Open a standard Web browser.
- In the browser, enter a URL for the target on which you want to enable the Application Web Server. The URL must conform to the following syntax:
- To set up the Application Web server on the local host system, enter the following URL:
- To set up the Application Web server on a remote target system, enter the following URL:
http://[remote device IP address] where [remote device IP address] is the actual IP address of the remote device.
Note On the local host system, you also can launch the URL by clicking the Configure Web Application Server button on the Web Server page of the Options dialog box.
- If necessary, install the Microsoft Silverlight browser plug-in. LabVIEW requires the Microsoft Silverlight browser plug-in to enable and configure the Application Web Server.
- Click the Install Microsoft Silverlight button or if the button does not appear, refer to the Microsoft Website at www.microsoft.com to download the Microsoft Silverlight plug-in.
- Follow the on-screen prompts to install the Microsoft Silverlight plug-in.
- After you finish the installation, refresh the browser or reenter the URL to display NI Web-Based Monitoring and Configuration.
- Click Login and enter a username and password to gain access to NI Web-Based Monitoring and Configuration for the system. If you have not established security settings for NI Web-Based Monitoring and Configuration on the system, enter the username Admin and a blank password to gain access using the default credentials.
- Click the Web Server Configuration button to display the Web Server Configuration page.
- Click Help for information about enabling and configuring the Application Web Server.
Creating a Web Service Project and Build Specification
- Create a LabVIEW Project to organize and build a Web service application.
- Add all Web method VIs such as add.vi to the project that you want to deploy as a Web service. You must add any Web method VI that has controls or indicators that exchange data over the network with Web clients. LabVIEW automatically includes any subVIs or VIs from the Web Services palette.
- (Optional) Add any HTML pages or images to the project that you want to deploy as part of the Web service application.
- (Optional) Add any auxiliary VIs to the project that you want to run independently of client requests and not exchange data with a Web clients.
- Save the project. Use the name Tutorial.lvproj if you want to match the figures throughout the remainder of the tutorial.
- Right-click Build Specifications and select New»Web Service (RESTful) from the shortcut menu.
- Complete the following steps on the Information page of the Web Service Properties dialog box to define the name of the Web service.
- Specify the Build specification name. This value only appears in the Project Explorer window under Build Specifications and must be unique among other build specification names.
- Specify a Service name such as the default WebService. The Service name is part of the URL that Web clients use to exchange data with Web method VIs and must conform to standard URL syntax. Web services also use the Service name to create the Web services .lvws file.
- Complete the following steps on the Source Files page of the Web Service Properties dialog box to include the Web method VIs and auxiliary VIs that you want to deploy as a Web service.
- Use the Add Item arrow to move at least one Web method VI such as add.vi from the Project Files tree to the Service VIs tree. A deployed Web service only includes VIs listed in the Service VIs tree. Moving a VI to the Service VIs tree displays the Configure RESTful VI dialog box for that VI.
- In the Configure RESTful VI dialog box, you can configure the VI as a Web method VI or an auxiliary VI, as well as the format that the VI returns data to the Web client. You also can configure the VI to use connector pane terminals or streaming to exchange data. For add.vi, use the default values.
- Complete the following items on the URL Mappings page of the Web Service Properties dialog box to build the URL mapping component of the URLs that Web clients use to access the Web method VIs. Web clients use the URL mapping to define which Web method VI to send a Web request and what, if any, values to assign to controls on the connector pane of the Web method VI.
- Create, edit, or view a URL mapping in the URL Mappings list. When you add a new Web method VI to the Service VIs tree on the Source Files page, LabVIEW creates a default URL mapping that includes the controls on the connector pane of the Web method VI. For add.vi, LabVIEW generates the default URL mapping /add/:a/:b. If a default URL mapping does not appear, or if you want to define additional URL mappings, click the Add URL Mapping button. You can configure multiple URL mappings for a single Web method VI, as well as URL mappings for multiple Web method VIs in a single Web service.
Note LabVIEW uses the name of the VI to build the default URL mapping. You do not have to use the VI name when you create URL mappings.
- Select a Web method VI such as add.vi to associate with the URL mapping using the Web method VI pull-down menu.
- Select the HTTP method to associate with the URL mapping using the HTTP method pull-down menu. Use the default GET value for add.vi. Specify the POST value for Web method VIs that accept post data.
- (Optional) Select a URL mapping and click the Override terminal defaults button to display the Override terminal defaults dialog box. Use this dialog box to always assign a specific value to a control on the connector pane of the Web method VI without requiring the Web client to specify that value in the URL.
- (Optional) Complete the following items on the Service Settings page of the Web Service Properties dialog box to configure service aliases and display a default HTML file when Web clients access a folder of static content.
- Place a checkmark in the Serve default index.html for static document folders checkbox when publishing static content in a Web service.
- Configure the Service Aliases menu to set up aliases for the Service name that you configured on the Information page of the Web Service Properties dialog box. In the URL that Web Clients use to exchange data with Web method VIs, Web clients can replace the Service name component with a service alias to further customize the URL.
- (Optional) On the Destinations and Source File Settings pages of the Web Service Properties dialog box, you can add static content such as HTML pages or images to a Web service. You do not need to configure these pages if you only publish Web method VIs and auxiliary VIs.
- (Optional) On the Advanced page of the Web Service Properties dialog box, place a checkmark in the Enable debugging checkbox if you want to enable remote debugging of a Web service. When you enable debugging, LabVIEW deploys both the front panel and block diagram for each Web method VI in the Web service. This increases the memory size of the deployed Web service files.
- (Optional) On the Preview page of the Web Service Properties dialog box, click the Generate Preview button to review the name and file location of the .lvws file that Web services use to package and deploy the application over the network. Save changes to VIs in memory before you create or edit a Web service build specification to ensure that the preview is accurate.
- Click the Build button to build the Web service and close the Web Service Properties dialog box. You also can right-click the Web service build specification in the Project Explorer window and select Build from the shortcut menu. After you build a Web service, you can deploy it to the Web server.
- In the Build status window, click the Done button to finish the Web service build process.
Deploying a Web Service to the Web Server
After you build the Web service, right-click the Web service build specification in the Project Explorer window and select Deploy from the shortcut menu. After you deploy the Web service, Web clients can exchange data with the included Web method VIs.
Accessing a Web Service
In a Web browser or other Web client, enter a URL to exchange data with a deployed Web method VI. The URL includes values from various dialog boxes in the Web service configuration process. The following figure shows an URL that a Web client might use to access the example Web method VI—add.vi—from earlier in the tutorial. This URL transmits two values from the Web client to the Web method VI. The example Web method VI adds these values and returns the sum as a Web page in the browser.
- IP address or computer name—If the Web client accesses the Web service from the same system running the Web server, use the value localhost. If the Web client accesses a Web service on a remote target, use the target's IP address or system name.
- Port—Matches the Port text box on the Application Web Server configuration page.
- Web service name—Matches the Service name option on the Information page of the Web Service Properties dialog box.
- URL mapping—Matches a URL mapping from the URL mappings page of the Web Service Properties dialog box.
- URL mapping terminal inputs—Matches terminal inputs configured as part of the URL mapping on the URL Mappings page of the Web Service Properties dialog box. For example, the URL mapping /add/:a/:b passes data to controls labeled a and b on the connector pane of add.vi. A Web client can submit the URL
http://localhost:82/WebService/add/5/8 to assign the value 5 to the a control and value 8 to the b control. The example add.vi, which adds two numbers, would return the sum 13 to the Web client as a Web page in the browser.