I am trying to consume a rest service to read Active MQ messages in C#. The service has a SSL certificate with no password. I can successfully get the response when I use the service url in browser (chrome, restlet client) but not in postman. I had added the certificate to Chrome before accessing the url.
This is a HTTPS service.
I have to call the service with the SSL cert along with my http request. I have tried WebRequestHandler, HttpWebRequest, HttpClient with no luck.
When I do that, I received the following error.
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
string url = System.Configuration.ConfigurationManager.AppSettings["ActiveMQDev"].ToString();
string certFileName = System.Configuration.ConfigurationManager.AppSettings["SSLCertPath"].ToString();
// create HTTP web request with proper content type
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.ContentType = "application/json;charset=UTF8";
X509Certificate2 cert = new X509Certificate2(certFileName);
request.ClientCertificates.Add(cert);
request.PreAuthenticate = true;
WebResponse response;
using (new ServerCertificateValidationScope(request, delegate { return true; }))
{
// call the web service and get response
response = request.GetResponse();
}
if (response != null)
{
//handle the response
}
this suppresses the exception but I get
RemoteCertificateNameMismatch
error in the callback(sender, certificate, chain, errors).
When I dont have the call to suppress the SSL error, I get a
401 unauthorized response from the server.
Any help is much appreciated. Thank you!
So we went back to the team that gave us the cert and it was faulty! We got a cert with password and its a pfx file now. We are directly accessing the queue now attaching the cert in the request. This seems to have resolved the issue with getting to the queue and accessing the messages in it. The only problem we have now is the messages are not dequeuing but i guess thats the AMQ team's headache. If anyone requires the code to access the AMQ directly using the NMS api, please send me a message. I can send a sample. Thanks all for your help. Really appreciate it.!