From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Setting up SSL for Web Services in LabVIEW 2009

Quick Backround

Web services were introduced in LabVIEW 8.6.  They enable you to connect to LabVIEW using standard RESTful web services.  To put it simply, if you can talk over HTTP, you can talk to LabVIEW using Web services.  If you're not familiar with this, or want more information, I recommend reading this article and consulting these FAQ.  Once you have successfully setup a secure server, the same steps are followed to deploy a VI as a Web Service.

Turning on SSL

Navigate to Tools >> Options and select 1) Web Server, 2) Enable Web Server 3) Create a New Server, since SSL cannot run on the default port 80, 4) I recommend setting the port to 443, since this is the default port for SSL.  If you don't do this, you'll have to type the port after the ip address of the server.

b7-31-2009 12-17-06 AM.png

Then scroll down and 5) Select SSL and 6) Click Okay.  You can leave the certificate file dialog blank if you intend to use the default file.

b7-31-2009 12-23-34 AM.png

At this point, you have enabled the server, but we need to go back and discover the certificate.  After closing this dialog, open it again by selecting 'Tools >> Options.'  Go back to the screen shown above and click 'Query.'  If this works, the SSL certificate File location should populate as shown below:

7-31-2009 12-39-10 AM.png

To check to make sure the server is running, go back to the Tools menu and select 'Distributed System Manager.'  If the server is setup and working properly, you should see something that looks like this:

7-31-2009 12-30-40 AMb.png

If for some reason this doesn't appear to work, go back to the web server configuration dialog in the option menu and try disabling and re-enabling the server.  You'll know it's working when you can go to a browser and type in "https://127.0.0.1"  Note the use of "https" instead of "http," which tells the browser that it is a secure connection and defaults the port to 443.  To use any other port, you will need to append it to the ip address, like "127.0.0.1:8000."

Every browser has a large list of signed root certificates. Obviously, the default LabVIEW certificate that is generated by your development environment is not signed or known by anyone, so your bowser will probably alert you.  If you click 'Continue,' you will see the default LabVIEW Web Server index page, which mens that everything is working.

7-31-2009 12-42-42 AM.png

Creating and Signing Your Own Certificate

If you want to have a certificate signed by someone, such as your IT department or VeriSign, you'll want to create a Certificate Signing Request.  To do this, launch the Distributed System Manager again from the Tools Menu.  Under 'NI_SSLConfiguration' select 1) 'OpenCSRs,' which is short for 'Open Certificate Signing Request,' and 2) click 'Create', 3) complete the signing request form 4) click 'submit.'  The text that appears in the following dialog is what will need to be reviewed and signed by whatever authority you so choose.

7-31-2009 12-47-24 AM.png

Elijah Kerry
NI Director, Software Community

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Elijah_K
Active Participant
Active Participant
on

Let me know what you think or if you have any questions.

Elijah Kerry
NI Director, Software Community
Jim_Kring
Trusted Enthusiast Trusted Enthusiast
Trusted Enthusiast
on

Hi, Eli. What is the preferred way to connect to a Web Service using SSL in LabVIEW?

Elijah_K
Active Participant
Active Participant
on

Are you asking about authentication specifically?

Elijah Kerry
NI Director, Software Community
Jim_Kring
Trusted Enthusiast Trusted Enthusiast
Trusted Enthusiast
on

No, not authentication.  Basically, I want an HTTPS client in LabVIEW.  Meaning, I want write a LabVIEW VI that talks to an LabVIEW Web Server that uses SSL (or any HTTP server that uses SSL)?  I know how to do this using the WinInet APIs, but I want a cross-platform solution (and I'd settle for a built-in solution for LabVIEW on Windows).

Rob_Calhoun
Member
Member
on

I second Jim's request. Right now we call WinHTTP to fetch URLs, but a built-in, cross-platform solution would be preferable.

LabView datasockets can be used to access http:// URLs, but they don't work for https://. Another annoyance with datasockets is that it is necessary to append [text] to the URL before reading binary data, e.g. "http://www.ni.com/images/global/us/logo.gif[text]". This is required to prevent Read Datasocket from throwing errors or corrupting data when reading the 99.999% of the web that isn't a LabView datasocket. (The ridiculous explanation for this is here: http://digital.ni.com/public.nsf/3efedde4v322fef19862567740067f3cc/f3cc5f7e60a75cb2862567e700696abf?OpenDocument .) Since the datasocket API can't really be changed at this point, a new GetURL function that handles http:// and https:// (and maybe file:// and ftp://...although everyone seems to be moving to http:// for even large downloads) seems like the best option.

Datasockets also used to crash LabView when they encountered a redirect, but that seems to be fixed in 8.6.1.

qm
Member
Member
on

any soltion to Jim and Rob's request?

Elijah_K
Active Participant
Active Participant
on

For the record, SSL enabled HTTP client VIs are available in LabVIEW as of 2010.

9-14-2011 11-34-42 AM.png

Elijah Kerry
NI Director, Software Community
Contributors