If your program uses the now legacy API System.Net.HttpWebRequest and that HttpWebRequest throws a System.Net.WebException that reads The operation has timed out.
Is it possible to change the timeout property in the System.Net.WebException via a web.config file by adding the correct add element name and value attribute?
Or possibly change it globally using the registry or a GPO?
I have already been advised to fix this using netsh http retries and some other settings and truth be told the issue could be on the opposite end of the connection where it also could be timing out; but it is unclear how to find that out.
The error looks like this:
System.Net.WebException: The operation has timed out.
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at System.WebServices.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
....
Could you clarify on how this relates to Powershell? I do see you mention Invoke-WebRequest but that command simply sends an HTTP request to a service, so don’t think it’s at the core of what you are trying to accomplish here.
I imagine the Invoke-WebRequest cmdlet and the .NETSystem.Net.HttpWebRequest library to use the same library to make calls to webpages; webservices and such.
So I figured that within the context of a web application since they both use the same library; maybe both could be effected by some global windows setting in the registry or through web.config in a .net webapp or using an argument about timeouts such as [-TimeoutSec <System.Int32>] that would change the same argument in the library function call of System.Net.HttpWebRequest.
I think it’s `TimeOutSec’ which in PS 7 i guess they changed how that works. I think OP hints at that potentially in response.
in any case in PS5
Specifies how long the request can be pending before it times out. Enter a value in seconds. The default value, 0, specifies an indefinite time-out.
A Domain Name System (DNS) query can take up to 15 seconds to return or time out. If your request contains a host name that requires resolution, and you set TimeoutSec to a value greater than zero, but less than 15 seconds, it can take 15 seconds or more before a WebException is thrown, and your request times out.
My concern still is, that impacts that command only and I’m not convinced that’s really what OP is asking as they continually use the word ‘global’. They could use default parameter values in PS but again, this impacts just that command. I guess i’m still confused on the actual problem OP is attempting to solve. It might help to back up a couple steps and explain the situation instead of trying to ask how to implement a solution would be helpful to provide context. It seems like OP is running an app and wanting to control the timeout from the app or something. I might need more coffee too as i just woke up from a nap haha.
dotnVo; thank you for taking my question seriously.
Yes, I am running a web-services based .NET application; it like most .NET web-based applications has an XML configuration file in which you can specify <add key="some-keyname" value="some-valuename" />.
After the application reaches out to the enterprise server with a webservices request; eventually it times out; but the error message does not make it clear if we are talking about a timeout that comes from the enterprise server end or if the timeout is coming from the client end on the machines that I work on and can control.
It simply says in a dialog box that pops up with a title that reads Error
System.Net.WebException: The operation has timed out
(again, it doesn’t specify if the time out came from my end or the enterprise end)…and it goes on…with the rest of the stack trace to tell us where the exception came from:
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at EGatewayClientCE.EGatewayService.BDSWse.ProcessDimeRequest()
...etc