G Web Development Software

cancel
Showing results for 
Search instead for 
Did you mean: 

Hosting a WebVI with requests from LabVIEW Web Service

Solved!
Go to solution

Hello,

 

I learned from this example how to create web application running on NI Web Server using LabVIEW Web Service to do some computation. I have no problem running on local machine, but when I try to open the web page on different machine in domain I only see WebVI but no results from LabVIEW Web Service.

 

My link looks like this: https://(machine name)/nxgproxy/55048/HtmlVI/Build/Web%20Server/Interactive/WebApp.gcomp/index.html 

I copied built project into C:\Program Files\National Instruments\Shared\Web Server\htdocs folder. HTTP method in LabVIEW looks like this: http://127.0.0.1:80/Web_Server/(VI name).

 

I tried different NI Web Server configurations - HTTP/HTTPS, CORS/no CORS,...  have deactivated firewalls on both server and client machines. But all in vain.

 

Obviously I have no problem with connection to remote machine NI Web Server but for some reason it does not communicate with LabVIEW Web Server on server machine.

 

 

Thank you for any help!

Marek.

0 Kudos
Message 1 of 7
(2,001 Views)

What error shows up in the browser error console?

~ The wizard formerly known as DerrickB ~
Gradatim Ferociter
0 Kudos
Message 2 of 7
(1,972 Views)

127.0.0.1/Web_Server/GM_Init:1
Failed to load resource:
net::ERR_CONNECTION_REFUSED

 

DeployedRun.min.js:23704
An unhandled error occurred on the LabVIEW diagram with code 363650 at HttpClientGet in NI::HTTP::httpWebServerClient.sli::httpWebServer_Get->NI::HTTP::GET.gvi->WebApp::index.gviweb<APPEND>
A network error has occurred. Possible reasons for this error include Cross-Origin Resource Sharing (CORS) configuration issues between the client and the target server or that the client cannot reach the target server. Due to browser security restrictions, detailed information about the cause of the network error cannot be provided. You may find specific details about the cause of the network error in the browser development tools console or in the LabVIEW output window.

LogLabVIEWError @ DeployedRun.min.js:23704
DeployedRun.min.js:23704
An unhandled error occurred on the LabVIEW diagram with code -375003 at Unflatten From JSON in WebApp::index.gviweb

LogLabVIEWError @ DeployedRun.min.js:23704
127.0.0.1/Web_Server/Monitoring:1
Failed to load resource: net::ERR_CONNECTION_REFUSED

DeployedRun.min.js:23704
An unhandled error occurred on the LabVIEW diagram with code 363650 at HttpClientPost in NI::HTTP::httpWebServerClient.sli::httpWebServer_Post->NI::HTTP::POST Buffer.gvi->WebApp::index.gviweb<APPEND>
A network error has occurred. Possible reasons for this error include Cross-Origin Resource Sharing (CORS) configuration issues between the client and the target server or that the client cannot reach the target server. Due to browser security restrictions, detailed information about the cause of the network error cannot be provided. You may find specific details about the cause of the network error in the browser development tools console or in the LabVIEW output window.

LogLabVIEWError @ DeployedRun.min.js:23704
DeployedRun.min.js:23704
An unhandled error occurred on the LabVIEW diagram with code 363531 at PropertyNode_PropertyWrite in WebApp::index.gviwebMinimum value (0) must be less than the maximum value (0).

LogLabVIEWError @ DeployedRun.min.js:23704

DevTools failed to load source map: Could not load content for : HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

DevTools failed to load source map: Could not load content for : HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

0 Kudos
Message 3 of 7
(1,942 Views)

As the error described, the likely reason is that CORS isn't being configured/applied properly.

 

You attached a screenshot showing that remote access is installed but that's different from CORS. The default setting when choosing insecure remote access in the configuration wizard actually disables CORS. Do you have it enabled here?

niwebcors.png

 

My assumption is you're probably trying to add CORS headers manually in the web service code itself but those get stripped by the server to prevent code that's running from having a say over CORS being enabled if it's not enabled at the server level.

~ The wizard formerly known as DerrickB ~
Gradatim Ferociter
0 Kudos
Message 4 of 7
(1,905 Views)

Looking at the screenshots I can see that the WebVI is trying to make a request to http://127.0.0.1:80/something on the diagram.

 

While that makes sense when the hosting server, labview web service, and the webvi running in a web browser are all running on the same machine:

 

MilanR_0-1679673554902.png

 

That does not work when the WebVI is running in a web browser on a separate machine. The URL hard coded in the diagram is pointing to the wrong server:

 

MilanR_1-1679673662071.png

 

So lets say you fix that and have the WebVI point to the correct server url on the diagram:

 

MilanR_2-1679674138749.png

 

Another thing I noticed is that it does not seem like the LabVIEW web service is deployed to the NI Web Server. It seems to be running on the application web server.

 

If that is true, the next issue you will hit is that the WebVI is hosted at a secure url with https enabled but is making a request to an insecure LabVIEW web server that is hosted via http. This is called a mixed content request and that is not allowed by browsers. A secure site making requests to an insecure site is blocked.

 

So you can fix that by either disabling https on the NI Web Server 😟 or by trying to enable HTTPS on the LabVIEW Web Service (not as easy as the NI Web Server).

 

But then as you continue development the next issue you will likely hit is that LabVIEW Web Services have limited support for CORS requests (due to being unable to respond to OPTIONS HTTP requests). This will restrict the types of Web Methods you can support in your LabVIEW Web Service among other restrictions.

 

If this all sounds really complicated to you it's because you are starting in the hard mode cross-origin configuration.

 

If you are just starting I strongly recommend going through the material and making the demos shown in the How to Build a Web UI for Your LabVIEW-Based Test System presentation.

 

The presentation discusses hosting the WebVI on the NI Web Server hosting service (which gives you a way to update WebVIs from a user interface instead of copying and pasting to a folder) and it shows how to deploy a LabVIEW Web Service to the NI Web Server so that your application runs in the much simpler same origin configuration:

 

MilanR_4-1679675378047.png

 

 

With the same-origin configuration you don't have to deal with CORS, you can use the NI Web Server in one spot to configure security settings, your LabVIEW Web Service is not restricted in the Web Methods you can use, running in the G Web Development IDE is easier, etc.

 

There are legitimate reasons to implement you system in a CORS configuration but I recommend starting with the approach shown in the presentation first.

 


Milan
Message 5 of 7
(1,896 Views)

Thank you both for the hints, so far I was trying out LabVIEW application server with https but with no luck. I'll follow your recommendations and let you know.

 

Marek

0 Kudos
Message 6 of 7
(1,815 Views)
Solution
Accepted by hlavam2

The webVI is finally functional without errors on other machines in domain. I did these steps:
1) Installed LabVIEW 2022 Q3 version (instead of LV 2019 which I think has no support for secure web server)

2) Started hosting my LabVIEW project on secure NI Web Server (https://127.0.0.1:443/Web_Server/...)
3) Enabled CORS in NI Web Server Configuration

hlavam2_0-1680090177822.png

4) Create HTTP requests using relative addressing instead of absolute

hlavam2_1-1680090487840.png

 

Thanks again for your help!

Marek

 

P.S.: these videos are very helpful:
How to Build a Web UI for Your LabVIEW-Based Test System - NI Community

NI Web Intro - HTTP, GET, & Dynamic Images - YouTube

 

Message 7 of 7
(1,774 Views)