Export (0) Print
Expand All

Understanding WebRequest Problems and Exceptions

WebRequest and its derived classes (HttpWebRequest, FtpWebRequest, and FileWebRequest) throw exceptions to signal an abnormal condition. Sometimes the resolution of these problems is not obvious.

Examine the Status property of the WebException to determine the problem. The following table shows several status values and some possible resolutions.

Status

Details

Solution

SendFailure

-or-

ReceiveFailure

There is a problem with the underlying socket. The connection may have been reset.

Reconnect and resend the request.

Make sure the latest service pack is installed.

Increase the value of the ServicePointManager.MaxServicePointIdleTime property.

Set HttpWebRequest.KeepAlive to false.

Increase the number of maximum connections with the DefaultConnectionLimit property.

Check the proxy configuration.

If using SSL, make sure the server process has permission to access the Certificate store.

If sending a large amount of data, set AllowWriteStreamBuffering to false.

TrustFailure

The server certificate could not be validated.

Try to open the URI using Internet Explorer. Resolve any Security Alerts displayed by IE. If you cannot resolve the security alert, then you can create a certificate policy class that implements ICertificatePolicy that returns true, and pass it to CertificatePolicy.

Refer to http://support.microsoft.com/?id=823177 for more information.

Make sure that the certificate of the Certificate Authority that signed the server certificate is added to the Trusted Certificate Authority list in Internet Explorer.

Make sure that the host name in the URL matches the common name on the server certificate.

SecureChannelFailure

An error occurred in the SSL transaction, or there is a certificate problem.

The .NET Framework version 1.1 only supports SSL version 3.0. If the server is using only TLS version 1.0 or SSL version 2.0, the exception is thrown. Upgrade to .NET Framework version 2.0, and set SecurityProtocol to match the server.

The client certificate was signed by a Certificate Authority (CA) that the server does not trust. Install the CA's certificate on the server. See http://support.microsoft.com/?id=332077 for more information.

Make sure you have the latest service pack installed.

ConnectFailure

The connection failed.

A firewall or proxy is blocking the connection. Modify the firewall or proxy to allow the connection.

Explicitly designate a WebProxy in the client application by calling the WebProxy constructor (WebServiceProxyClass.Proxy = new WebProxy(http://server:80, true)).

Run Filemon or Regmon to ensure that the worker process identity has the necessary permissions to access WSPWSP.dll, HKLM\System\CurrentControlSet\Services\DnsCache or HKLM\System\CurrentControlSet\Services\WinSock2.

NameResolutionFailure

The Domain Name Service could not resolve the host name.

Configure the proxy correctly. See http://support.microsoft.com/?id=318140.

Ensure that any installed anti-virus software or firewall is not blocking the connection.

RequestCanceled

Abort was called, or an error occurred.

This problem might be caused by a heavy load on the client or server. Reduce the load.

Increase the DefaultConnectionLimit setting.

See http://support.microsoft.com/?id=821268 to modify Web service performance settings.

ConnectionClosed

The application attempted to write to a socket that has already been closed.

The client or server is overloaded. Reduce the load.

Increase the DefaultConnectionLimit setting.

See http://support.microsoft.com/?id=821268 to modify Web service performance settings.

MessageLengthLimitExceeded

The limit set (MaximumResponseHeadersLength) on the message length was exceeded.

Increase the value of the MaximumResponseHeadersLength property.

ProxyNameResolutionFailure

The Domain Name Service could not resolve the proxy host name.

Configure the proxy correctly. See http://support.microsoft.com/?id=318140 for more information.

Force HttpWebRequest to use no proxy by setting the Proxy property to null.

ServerProtocolViolation

The response from the server is not a valid HTTP response. This problem occurs when the .NET Framework detects that the server response does not comply with HTTP 1.1 RFC. This problem may occur when the response contains incorrect headers or incorrect header delimiters.RFC 2616 defines HTTP 1.1 and the valid format for the response from the server. For more information, see http://www.ietf.org.

Get a network trace of the transaction and examine the headers in the response.

If your application requires the server response without parsing (this could be a security issue), set useUnsafeHeaderParsing to true in the configuration file. See <httpWebRequest> Element (Network Settings).

Community Additions

ADD
Show:
© 2015 Microsoft