John Lokanis Posted April 9, 2015 Report Share Posted April 9, 2015 I am calling a web service using system.net.webclient(). So far it is working fine but now I want to set the timeout to something other than the default. Unfortunately, the timeout is not an exposed property for webclient(). From what I have read, webclient() is a child of the httpwebrequest() class, and that class has a timeout that can be set. But httpwebrequest in system (2.0.0.0) has no public constructors. All the examples on the web show how to override the webrequest getter to set a different timeout. Unfortunately this exceed my .net skills. Does anyone know how to solve this in LabVIEW? Here is the C# example: http://stackoverflow.com/questions/1789627/how-to-change-the-timeout-on-a-net-webclient-object NOTE: I am trying to solve this problem in LabVIEW 2011 so am stuck with .NET 2.0 for the system assembly. thanks, -John Quote Link to comment
ak_nz Posted April 9, 2015 Report Share Posted April 9, 2015 Quick thought - you could probably down-cast the reference and then set the TimeOut and ReadWriteTimeOut properties on the HttpWebRequest reference. Quote Link to comment
John Lokanis Posted April 9, 2015 Author Report Share Posted April 9, 2015 Tried that. Cannot cast the webclient() to the webrequest() or the httpwebrequest(). I think it is because the webclient() is not a child but rather uses webrequest(). So, I need to create a webrequest() object, set the timeout and then tell webclient() to use my version. But I have no idea how to create a .net object that inherits from the base class and then instantiate the webclient using my new object. Quote Link to comment
ak_nz Posted April 9, 2015 Report Share Posted April 9, 2015 (edited) In order to create an HTTPWebRequest: there is a factory method in the base class WebRequest: https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(v=vs.110).aspx. You could then call GetWebResponse to process a response object. "The HttpWebRequest class provides support for the properties and methods defined in WebRequest and for additional properties and methods that enable the user to interact directly with servers using HTTP. Do not use the HttpWebRequest constructor. Use the WebRequest.Create method to initialize new HttpWebRequest objects. If the scheme for the Uniform Resource Identifier (URI) is http:// or https://, Create returns an HttpWebRequest object." EDIT: Looks like you can only call GetWebResponse on derived classes as you specified. It looks like the WebClient class design exposes this as a virtual seam to override. LabVIEW can't create .NET classes, so in this case you could wrap it up in a basic assembly and use that from LabVIEW. Or use the LabVIEW native APIs to communicate to the web service. Edited April 9, 2015 by ak_nz Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.