Company Events Academic Community Support Solutions Products & Services Contact NI MyNI

Understanding URL Mappings and Query Strings in Web Services (Real-Time, Windows)

LabVIEW 2013 Help

Edition Date: June 2013

Part Number: 371361K-01

»View Product Info

Parent Topic: Sending Data to a Published Application using URLs

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.

Web clients use URLs to exchange data with published Web services. URL mappings and query strings are parts of the URLs:

  • URL mapping—Serves as the identifier the host web server uses to direct an HTTP request to a specific HTTP method VI or static file. Each HTTP method VI and static file has one URL mapping.
  • Query string—Identifies and assigns values to input parameters on the connector pane of the HTTP method VI. You can append input parameters to the end of a URL mapping by appending a question mark, a control label, an equals sign, and the value to assign the control.

For an HTTP method VI named Add.vi, LabVIEW automatically defines the URL mapping as /Add. If the VI contains the inputs a and b, the URL and query string /Add?b=2&a=3 assigns values to the inputs. In this example, the URL a client uses is http://127.0.0.1:8080/WebService/Add?b=2&a=3.

Note  Instead of using default URL mappings, you can customize URL mappings, which affects how you assign values to input parameters of an HTTP method VI.

Omitting Input Parameter Values from Query Strings

A client can omit any input parameters from the query string. If a client omits an input parameter value, the Web service uses the default value for the input terminal stored in the VI. For example, given an HTTP method VI named Add.vi with controls labeled a and b, HTTP requests using the following URL mappings and query strings are valid:

  • /Add?b=2&a=3
  • /Add?a=3 (uses default value of b control)
  • /Add?b=2 (uses default value of a control)
  • /Add (uses default values of both controls)

Customizing URL Mappings

Typically, you can use the default URL mappings for a Web service. However, in advanced use cases, you might want to customize the URL mapping for an HTTP method VI. Complete the following steps to configure a custom URL mapping for an HTTP method VI:

  1. Right-click the Web service project item and select Properties.
  2. Browse to the HTTP Method VI Settings page of the Web Service Properties dialog box.
  3. Select the HTTP method VI whose URL mapping you want to customize from the table of VIs.
  4. On the URL Mapping tab, remove the checkmark from Use standard URL mapping to make the URL textbox editable. You now can edit the portion of the URL after the name of the Web service and the web resource to which the VI belongs, if applicable. In other words, you cannot edit the IP address, port, Web service name, or web resource name (if any).

You can configure the URL mapping string as any value as long as the value begins with a forward slash and uses standard HTTP syntax. You can append input parameters to the end of a URL mapping by adding a forward slash, a colon, and the label of a connector pane input in the associated HTTP method VI. Note that this syntax is different from how you append query strings to default URL mappings to set parameter values.

An example of a custom URL mapping string is /Add/:a/:b. The URL mapping string /Add is the base of the URL mapping and /:a/:b configures input parameters for the HTTP method VI. If the URL mapping contains no input parameters to pass to the HTTP method VI, the VI must contain default values for any input terminals.

Passing Multiple Fragments using URL Mappings

You can create a custom browsing URL that assigns multiple fragments of the URL to a single string input terminal of the HTTP method VI. This technique is useful for passing file paths or other hierarchical values using a custom browsing URL.

For example, /:x/*y creates an input parameter for a control labeled x and a control labeled y when appended to a URL mapping. You then can append a value, such as /test/C/directory, to the custom browsing URL that corresponds to the input parameter /:x/*y that you added to the URL mapping. In this example, x is assigned test and y is assigned C/directory. The input parameter that contains more than one fragment must occur at the end of the custom browsing URL.


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit