LabVIEW, web services and optional inputs

LabVIEW has an import web services module for several versions, and it’s quite a useful tool.

After an import your WSDL specification (the web service) has been translated into a .net library, and an accompanying LabVIEW library with proxy support.

The tool is pretty good and straightforward, but lacks one little detail: support for optional input that aren’t arrays or strings.

Optional inputs in web services are sent as a NULL object via the XML data, but that’s not working for booleans, timestamps and numerics since these data types have a valid value that can be null. In the web service definition (WSDL) this is shown with the following XML:

<s:element name="GetGlobalTable">
<s:element minOccurs="1" maxOccurs="1" name="from" type="s:dateTime"/>
<s:element minOccurs="1" maxOccurs="1" name="to" nillable="true" type="s:dateTime"/>
<s:element minOccurs="1" maxOccurs="1" name="highImpactCount" nillable="true" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="trainPassageID" nillable="true" type="s:int"/>

Elements that are nullable (arrays and string) have a minOccurs value of 0, data types that aren’t nullable have a nillable=’true’ field in the definitions.

The code generated by the web service importer for these nillable datatypes isn’t working ‘out of the box’:


Since the properties are read-only we can only read the value but not update, however the Nullable class is correct, so we need to recreate these classes.

The fix is quite easy (once you’ve figured it out):


This is a snippet from a VI dedicated to generate a nullable I32. With a parameter we decide whether the object is NULL, if that’s the case we just output a constant NULL.

If the parameter isn’t optional we use the LabVIEW supplied ‘To .Net Object’ to generate a basic .NET object, that we upcast to a Nullable of the appropriate type. The output is feeded into the .Net method for getting data.

This method works the same for booleans and timestamps.

1 comment:

  1. Thanks Ton. That helped me out a lot - I was getting quite frustrated trying to figure this out!