简体   繁体   中英

HTTPS web service call from form works and from inside IIS doesn't

I have a Web App that in one of it's processes needs to call a https web service in an external server.

When I make the call I get a this exception: An error occurred while making the HTTP request to https://servicos.portaldasfinancas.gov.pt:701/sgdtws/documentosTransporte. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server. An error occurred while making the HTTP request to https://servicos.portaldasfinancas.gov.pt:701/sgdtws/documentosTransporte. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.

The inner exception is: The underlying connection was closed: An unexpected error occurred on a send.

In order to debug, I created a windows form application that used exactly the same code and did exactly the same call, and accessed the same certificate for the call. But on the windows form application the call goes through without a problem.

I'm at a loss as to what could be causing the connection to fail from inside IIS and don't know what could be different between the two.

I identified the problem and managed to find a solution.

The problem was that the code was using a certificate that the logged user had access to but IIS didn't. In order to install the certificate in a way that IIS has access to it you need to:

  1. On MMC.exe add the Local Computer Certificate Store view
  2. Install the certificate on that store's Personal > Certificates
  3. Check the Exportable option as you install the certificate
  4. After the certificate is installed confirm that the whole certificate chain is trusted. If a link in the chain shows a red cross indicating it is not trusted, copy that certificate to the Trusted Root Certification Authorities folder.
  5. Restart IIS just to be safe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM