HttpWebRequest.GetRequestStream() breaks by timeout on SSL connection under Windows 7/Vista

后端 未结 2 1100
暗喜
暗喜 2021-02-20 03:52

I have an C# windows application (.Net 3.0 Framework) that makes a call to PHP web service using HttpWebRequest.

In Win 7 & Vista, if the call is

2条回答
  •  不要未来只要你来
    2021-02-20 04:35

    This error cropped up in a working C# application after migrating the website being accessed to a new server, and that indicated a server-side problem. Indeed, we finally resolved this issue by setting the "ServerName" value in the Apache configuration file to match the domain name registered in the certificate. (Another forum mentioned that setting "ServerAlias" would also work.)

    More specifically, the httpd.conf file for the SSL site had the following in the VirtualHost section:

    ServerName www.secure.mydomain.com
    

    The certificate was registered to secure.mydomain.com, and the URL we were accessing was also https://secure.mydomain.com/test.html.

    So simply changing the conf file to the following and restarting Apache did the trick:

    ServerName secure.mydomain.com
    

    The following would have also worked, most likely:

    ServerName www.secure.mydomain.com
    ServerAlias secure.mydomain.com
    

    Here's some additional background information, for future reference:

    The two errors we saw in the System.Net.trace.log were:

    System.Net.Sockets Error: 0 : [4316] Exception in the 
        Socket#18796293::Receive - A blocking operation was 
        interrupted by a call to WSACancelBlockingCall
    System.Net Error: 0 : [4316] Exception in the 
        HttpWebRequest#35191196:: - The operation has timed out
    

    Here are all the things we tried which did not resolve the issue:

    • installing intermediate certificates from the SSL certificate issuer into Apache (this is required)
    • changing user agent in web request (no effect)
    • changing server-side and client-side time-outs and memory limits (no effect)
    • testing with a static page (no effect)
    • testing with other https sites (they worked fine)
    • adding the cert to the trusted certificates store (no effect)
    • purchase and install a certificate from a different certificate issuer (no effect)
    • compare virtual host .conf files from a known working server to the problem server (this led us to resolve the issue)

    The https URL could be opened in Opera, IE8, and Firefox without any problems. WGET for Windows complained about an invalid certificate, but then again, WGET is an old application and does not appear to trust as many certificates.

    The C# client application worked under Windows XP, but not in Windows 7 or Windows Vista. It appears that Windows 7 and Vista are more aggressive about validating the certificate. They do not provide an informative error message when it fails, and instead simply time out during the SSL handshake.

提交回复
热议问题