Imagine you have two applications, A & B, running on the same web server. You want app A to call a webService on app B over SSL.
Is it possible to do that with an address like https://localhost/appsB/webService1
?
How can the SSL handshake be done without a client (like a browser?)
It actually works when using this address http://localhost/appsB/webService1
, only not in SSL mode.
However it works as well with HTTPS between the server and a browser when calling https://localhost/appsB/webService1
.
Now, the strange thing is that it works sometimes but randomly fails when calling the webService on app B using HTTPS. Using HTTP it always works.
My tests are on IIS7.0 with a valid ssl certificate from Thawte with SSL option not required for app B.
Here is an exemple of my code :
string baseAddress = "http://localhost";
//or string baseAddress = "https://localhost";
var baseUri = new Uri(baseAddress);
//final url for appB
finalUrl = baseAddress + httpContext.Current.Request.ApplicationPath.TrimEnd('/') + "/" + url;
//Add a cookie to retrieve good contexte on appB
var cookieContainer = new CookieContainer();
using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
using (var client = new HttpClient(handler) { BaseAddress = baseUri })
{
cookieContainer.Add(baseUri, new Cookie("ASP.NET_SessionId", HttpContext.Current.Session.SessionID));
HttpResponseMessage response = client.GetAsync(finalUrl).Result;
Dictionary<string, dynamic> sData;
if (response.IsSuccessStatusCode)
{
etc, etc..
}