I have a .NET web service that I want to be accessed over https rather than http. Problem is HOW !!
Solution:
- Activate SSL on web server (IIS)
- Specify the file for which SSL is required
- Through inetmgr, browse to the file (in my case the .asmx file). Right click -> Properties -> File Security -> Secure Communications -> Edit
- Check Require SSL Channel (SSL)
And you should be done.
Related useful article:
CONSUMING WEBSERVICES OVER HTTPS (SSL)
Module: CEmailManager
Calling function:
public static bool SendDummyEmail()
{
return SendEmail(CGlobalParams.AdminEmail, "dummy", "Hi");
}
Worker function:
private static bool SendEmail(string p_strTo, string p_strSubject, string p_strBody)
{
try
{
MailMessage objMessage = new MailMessage();
string[] lstRecipient = p_strTo.Split(',');
foreach (string strTo in lstRecipient)
{
objMessage.To.Add(strTo);
}
objMessage.From = new MailAddress(CGlobalParams.SMTPUser, CGlobalParams.EmailSenderDisplay);
objMessage.Subject = p_strSubject;
objMessage.Body = p_strBody;
SmtpClient objClient = new SmtpClient(CGlobalParams.SMTPServer, CGlobalParams.SMTPPort);
objClient.UseDefaultCredentials = false;
objClient.Credentials = new System.Net.NetworkCredential(CGlobalParams.SMTPUser, CGlobalParams.SMTPPassword);
objClient.DeliveryMethod = SmtpDeliveryMethod.Network;
if (CGlobalParams.SMTPRequireSSL)
{
objClient.EnableSsl = true;
}
objClient.Send(objMessage);
return true;
}
catch
{
return false;
}
}
Where
CGlobalParams: A class responsible for reading values for global parameters
Global parameters used here:
SMTPPassword : somevalue
SMTPPort : 587
SMTPRequireSSL : true
SMTPServer : smtp.gmail.com
SMTPUser : jyotsnas@philogy.com
With currently set global parameters, the code sends email with gmail/ google apps over SSL. Setting the SMTPRequireSSL to false, will make the code send email with SMTP server which requires authentication but not SSL.