Click here to Skip to main content
15,868,141 members
Articles / Web Development / HTML

Common Problems while Consuming Web Services over SSL in .NET

Rate me:
Please Sign up or sign in to vote.
3.15/5 (8 votes)
11 Jul 2009CPOL3 min read 88.7K   16   8
Common problems and solutions while consuming SSL enabled web services in .NET

Introduction

Security is a general concern with web services because SOAP (request and response) messages are exchanged (between web service and client) in a plain text format. Though with WSE 2.0/3.0 and WCF, it is very much possible to encrypt the sensitive information in the message, it is a commonly accepted practice to use SSL (HTTPS) communication.

This article discusses the problems that generally pop-up when a SSL enabled (self-signed/test certificate) service is consumed by a .NET application.

Background

To implement SSL on your web service, you need to get and install a certificate issued by a Certificate Authority (CA) on your web server (IIS). Mostly this certificate is used only in production environments. When it comes to development and test environments, a self-signed certificate (test certificate) is being used. You can generate a test certificate using MakeCert.exe tool (included in the .NET Framework SDK) or using (IIS) 6.0 Resource Kit Tools.

Problem #1

When you try to access an SSL enabled web service from your C# code, you will get the following error....

"The underlying connection was closed: Could not establish trust relationship 
with remote server." 

This is true with a test (self-signed) certificate or a certificate issues by CA where the host name and the name on which the certificate was issued don't match - Perhaps you might be accessing it through an external IP address.

Root Cause of Problem #1

How many times have you observed the following windows in your browsers when browsing an HTTPS web page or a web service?

Internet Explorer 8 displays the following message:

Image 1

Firefox 3.0.10 displays the following message:

Web_Service_Error_in_FireFox

Google Chrome displays the following message:

Image 3

All the three browsers (Internet Explorer 8, Firefox 3.0.11 and Chome) are asking the user to choose between closing the window or adding an exception because they couldn't verify that this certificate is being issued from a valid CA.

Solution to Problem #1

When you are accessing the web service through your C# code, you should do the same as what you have done in the browser - Trust the certificate!!. But there is no message window for you to accept it when you are accessing it programmatically. So you just need to simulate the message windows and ask it to trust the certificate.

Here is code to simulate the message window.

Add the following code just before invoking a web service method:

C#
ServicePointManager.ServerCertificateValidationCallback
= delegate(Object obj, X509Certificate certificate, X509Chain
chain, SslPolicyErrors errors) 
return (true); };

Problem #2

Sometimes even after implementing Solution #1, you might get the following error:

Server was unable to process request. ---> Unable to generate a temporary
class (result=1).
error CS2001: Source file 'C:\WINDOWS\TEMP\zezde3bz.0.cs' could not be found
error CS2008: No inputs specified

Root Cause of Problem #2  

Two different settings can cause this problem:

  1. ASPNET and IUSR users in your system do not have read/write access to 'C:\WINDOWS\TEMP\.
  2. Your work station is in a different network domain and its WORKGORUP is different. Trust me on this!! In corporate environments where we work in multiple domains (clients and our employers), it is very much possible that you are logging into the system with your employer domain login credentials and your IP address is in your client domain.

Solution to Problem #2

Needless to say, the solution is straight forward:

  1. The permission problem can be caused by an improper .NET Framework installation. You can re-install the framework or you can just add permissions to ASPNET and IUSR users on 'C:\WINDOWS\TEMP\
  2. In the second case, what worked for me is either you should use a local login and your work station is not in any workgroup or your workstation is in the same workgroup as that of its network domain.

History

  • 11th July, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer Bank of America
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionI think this is by pass technic to HTTPS. Pin
ravirajput85@gmail.com1-Jul-14 23:23
ravirajput85@gmail.com1-Jul-14 23:23 
QuestionThanks nice article Pin
sunny_mittal28-May-14 11:51
sunny_mittal28-May-14 11:51 
QuestionMissing { in ServerCertificateValidationCallback code Pin
chu2862120-Apr-12 5:31
chu2862120-Apr-12 5:31 
QuestionA good article! Pin
Nguyen Thanh Luc11-Oct-11 17:21
Nguyen Thanh Luc11-Oct-11 17:21 
QuestionVery helpful. Pin
daviessolutions5-Aug-11 6:23
daviessolutions5-Aug-11 6:23 
General[My vote of 1] nothing new Pin
Md. Marufuzzaman11-Jul-09 6:31
professionalMd. Marufuzzaman11-Jul-09 6:31 
GeneralRe: [My vote of 1] nothing new Pin
Kishore Nandagiri11-Jul-09 18:44
Kishore Nandagiri11-Jul-09 18:44 
GeneralRe: [My vote of 1] nothing new Pin
Sathishkumar_P23-Aug-11 0:00
Sathishkumar_P23-Aug-11 0:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.