Example Code

HTTP Request Using .NET Controllers in LabWindows/CVI

Code and Documents

Attachment

There are multiple ways of forming an HTTP request in LabWindows/CVI 2012. One of these ways is to create a .NET Controller, which generates function panels capable of utilizing the Microsoft .NET Framework.

First, please look over the following MSDN article on using .NET to make HTTP requests:


http://msdn.microsoft.com/en-us/library/cc197953


This example uses the WebClient class. There is an example for using this class to make an HTTP request here:


http://www.codeproject.com/Articles/33798/HTTP-GET-with-NET-WebClient


All that is left is to translate this C# code into C code in LabWindows/CVI. The key thing to remember here is that each .NET class has an assembly associated with it. LabWindows/CVI can create C wrapper functions for these assemblies if you create a .NET controller out of them by clicking Tools>>Create .NET Controller. Details of this process can be found here:


http://zone.ni.com/reference/en-XX/help/370051V-01/cvi/usermanual/createcvidotnetcontrollerdb/


This example uses .NET controllers for the System and mscorlib assemblies from the .NET 4.0 Framework. These controllers must be created in order to execute this code.


In order to demonstrate functionality, this simple example pings http://www.google.com and prints its response string.

Other product and company names mentioned herein are trademarks or trade names of their respective companies.

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

Comments
Pete_Cooper@Genie_Industries
Member
Member
on

I incorporated this code into my CVI project and it works! Great product example.

vix
Active Participant
Active Participant
on

I tested the code and basically it works, but I noticed that the first time the OpenRead is executed it is really slow.

I googled a lot and it seems it's more or less what is described here

I tried to follow the suggestion given in that thread, but I can't find a way to set the proxy to WebClient.

How can I do this?

Vix
-------------------------------------------
In claris non fit interpretatio

-------------------------------------------
Using LV from 7
Using LW/CVI from 6.0
Pete_Cooper@Genie_Industries
Member
Member
on

I am not familar with what you are trying to do but I found a web site that might help:

http://stackoverflow.com/questions/11228744/how-to-add-proxy-authentication-details-to-webclient-obj...

In our application talking to our device on the network the first time the OpenRead method is called it is slow. Once we have a connection, then the OpenRead call is extremely fast (about 40 ms). The CVI /.Net code for our application is very similar to what NI provided as an example here. The internet device that is on our network is setup that way for the first time reads and that is why it is slow on the network. 

zubik
Member
Member
on

Hi , where can I find system.h file (in HTTP example it appears in includes ) .

Thanks

Pete_Cooper@Genie_Industries
Member
Member
on
Pete_Cooper@Genie_Industries
Member
Member
on

The previous person Frank L. submitted a zip file for a CVI project that did not include the "System.h" file. The assumption was the "System.h" file would be generated with CVI's "Create .NET Controller" (Tools->Create .NET Controller). If one were to generate the "System.h" file with "Create .NET Controller" on their own, it would take a lot of time for CVI to generate this file. Since the "system.h" file was not submitted with the current zip file and project and for clarity and to save time,  I re-submitted the zip file with the correct header file from <National Instruments CVI Path>\samples\dotnet that now includes the SystemWrapper.h (replaces the System.h file), SystemWrapper.fp, mscorlib.h and mscorlib.fp files. The project should now compile and execute correctly as is.

vix
Active Participant
Active Participant
on

This code is really useful and I've been using for some months.

I've just noticed that I see some problems with characters like é, è, ò, à, ... that are shown as ?

I double checked and the server returns the expected characters.

Maybe there is some problems with the encoding.

How can I specify the encoding with this example?

Vix
-------------------------------------------
In claris non fit interpretatio

-------------------------------------------
Using LV from 7
Using LW/CVI from 6.0
Contributors