Jump to content

Setting the timeout for a web service call using .NET


Recommended Posts

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:


 

NOTE: I am trying to solve this problem in LabVIEW 2011 so am stuck with .NET 2.0 for the system assembly.

 

thanks,

 

-John

Link to comment

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.

Link to comment

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 by ak_nz
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.