Hi!
I'm attempting to connect to an internal .net Web Service using a certificate file. I see that the old SoapConnection object had the SetClientCertificateFile method, but can't find the same (or similar) method in the RESTClient or HTTPClient. Does anyone know how to pass a certificate to a Web Service using HTTP or REST?
Thanks!
Thanks! Do those methods (SetOptions and SetClientCertificateFile) modify the request header? Essentially, what I'm attempting to do is something along these lines in PB Classic:
public static X509Certificate2 GetClientCertificate()
{
var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
string certCode = ConfigurationManager.AppSettings["certCode"].ToString();
X509Certificate2Collection certificatesFound;
try
{
store.Open(OpenFlags.ReadOnly);
//Specify the SPID certficate serial number to intiate the certificate
certificatesFound = store.Certificates.Find(X509FindType.FindBySerialNumber, certCode, true);
store.Close();
if (certificatesFound == null || certificatesFound.Count == 0)
{
throw new InvalidOperationException("Could not find a certificate!");
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (store != null)
store.Close();
}
return certificatesFound[0];
}
1. I suggest you upgrade your PB to PB 2019 R2 Build 2323 and use the new module of .NET DLL Importer. You can compile the code as a C# simple class to a DLL file and then import it to PB to pass the same function. You can find it in the local Help documentation and how to invoke it.
https://docs.appeon.com/appeon_online_help/pb2019r2/application_techniques/ch20s02.html
Note: currently some complex C# classes do not support it. You can refer to the below link:
https://docs.appeon.com/appeon_online_help/pb2019r2/application_techniques/ch20s01.html
2. You can also refer to the following link and see how another customer resolves this problem.
https://community.appeon.com/index.php/qna/q-a/call-rest-web-service-with-certificate?limitstart=0#reply-9854
Regards,
the link you posted refers to a 3rd party library and marks that library as accepted solution.
Nothing against that, Chilkat is a very good set of API and I too use it sometimes.
But I think a solution in this forum should be a a little bit more creative than just purchasing an external tool.
I like the idea of using .NET DLL importer. In that way it is possibile to use System.Net.HttpWebRequest and its ClientCertificates.Add() API for passing the certificate file.
A temporary solution until HTTPClient will provide built-in certificate support. :-)
Best,
.m