We are trying to connect to an external api from our organisation via soap. When we do the connection via soap ui with the wsse security as binarysecuritytoken(using pfx certificate) it works fine and yields the expected output. Since we are going to call the API programmatically we are doing the same in C#(beginner level expertise) but the binarysecurity token we generate by exporting the pfx certificate doesnt match with the one generated by soapui. We are using the below code to generate the token..
When we try the below option the error is - ASN1 parse of PKIPath Failed
Option 1
var c= new X509Certificate2(PFXFilePath, CertificatePassword);
var export = c.Export(X509ContentType.Cert, CertificatePassword);
var base64 = Convert.ToBase64String(export);
Option 2
var c= new X509Certificate2(PFXFilePath, CertificatePassword).GetPublicKey();
var base64 = Convert.ToBase64String(c);
TOken generated by Option 2 is a subset of the token generated by SOAP UI
I have dugged around a lot into SO archives and couldnt find the correct solution for this. Please help