web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Error while loading client certificate in CRM Plugin

(0) ShareShare
ReportReport
Posted on by 362

Hi Everyone,

I am trying to call the web service which is hosted in SAP server from CRM plugin. The web service is User Name, Password and Client Certificate protected. I stored the certificate in web resource as mentioned in the below blog

http://mileyja.blogspot.in/2011/04/storing-any-file-type-in-microsoft.html

I have written the following code to retrieve the certificate and provide it to web service.


QueryExpression getWebResource = new QueryExpression("webresource");

getWebResource.ColumnSet = new ColumnSet(new string[] { "name", "content" });
getWebResource.Criteria.AddCondition(new ConditionExpression("name", ConditionOperator.Equal, webResourceName));
EntityCollection webResources = service.RetrieveMultiple(getWebResource);
if (webResources.Entities.Count > 0)
{
Entity webResource = webResources.Entities[0];
byte[] clientCertificate = Convert.FromBase64String(webResource.Attributes["content"].ToString());
X509Certificate2 _clientCert = new X509Certificate2(clientCertificate);
if (_clientCert != null)
{
serviceClient.ClientCredentials.ClientCertificate.Certificate = _clientCert;
}
}

above code is failing at the highlighted line with the "Cannot find the original signer" error. Any thoughts, how to fix this issue.

I am using CRM Online 2016 and trying to connect the web service hosted in SAP PI

Thanks,

Phani.

*This post is locked for comments

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello Phani,

    Have you tried running the same code from console app? If you tried and it works the answer is sandboxing of plugins.

  • PHANI RAJA SEKHAR TUMMALAPALLI Profile Picture
    362 on at

    Hi Andrew,

    Thanks for the reply. I can't test it from console app as they have opened the firewall for MS CRM IPs only

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Phani,

    If you get issue on the line you outlined then you don't need your IP to be white-listed because as far as I understood you experience issue on the line where you try to instantiate your certificate. So try it from console as I suggested.

  • PHANI RAJA SEKHAR TUMMALAPALLI Profile Picture
    362 on at

    Ok, I will let you know in a while

  • PHANI RAJA SEKHAR TUMMALAPALLI Profile Picture
    362 on at

    Hi Andrew,

    Same error from console app also. The following is the full code that I have written in console app

    IOrganizationService service = CrmService.InitializeServiceProxy();

    //Initialize Binding

                   BasicHttpsBinding hBind = new BasicHttpsBinding();

                   hBind.Security.Mode = BasicHttpsSecurityMode.Transport;

                   hBind.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

                   hBind.MessageEncoding = WSMessageEncoding.Text;

                   hBind.MaxReceivedMessageSize = int.MaxValue;

                   // Retrieve Service url from Config entity

                   Uri webServiceUrl = new Uri(serverURL);

                   //Intialize ServiceClient on Address

                   EndpointAddress eAddress = new System.ServiceModel.EndpointAddress(webServiceUrl);

                   QuoteLine_Create_OutClient serviceClient = new QuoteLine_Create_OutClient(hBind, eAddress);

                   // Retrieve credentials from config entity

                   serviceClient.ClientCredentials.UserName.UserName = userName;

                   serviceClient.ClientCredentials.UserName.Password = password;

                   QueryExpression getWebResource = new QueryExpression("webresource");

                   getWebResource.ColumnSet = new ColumnSet(new string[] { "name", "content" });

                   getWebResource.Criteria.AddCondition(new ConditionExpression("name", ConditionOperator.Equal, webResourceName));

                   EntityCollection webResources = service.RetrieveMultiple(getWebResource);

                   if (webResources.Entities.Count > 0)

                   {

                       Entity webResource = webResources.Entities[0];

                       byte[] clientCertificate = Convert.FromBase64String(webResource.Attributes["content"].ToString());

                       X509Certificate2 _clientCert = new X509Certificate2(clientCertificate);

                       if (_clientCert != null)

                       {

                           serviceClient.ClientCredentials.ClientCertificate.Certificate = _clientCert;

                       }

                   }

    Any suggestions?

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    That means that you have issues with loading of the certificate itself and not with issues with sandboxing of plugins.

    Check this thread - stackoverflow.com/.../loading-x509certificate-results-in-exception-cryptographicexception-cannot-find it looks like your issue. Good luck.

  • Verified answer
    PHANI RAJA SEKHAR TUMMALAPALLI Profile Picture
    362 on at

    Hi Andrew,

    I resolved this issue.

    Cause: Inside of my certificate file, there are two certificates. So I have to load the file as Certificate Collection and find the correct one

    Code:

    X509Certificate2 targetCertificate = null;

    X509Certificate2Collection certCollection = new X509Certificate2Collection();

    certCollection.Import(<byte 64 Content from web resource>);

    certCollection = certCollection.Find(X509FindType.FindBySubjectName, subjectName, true);

    if (certCollection.Count > 0)

    {

       targetCertificate = certCollection[0];

    }

    return targetCertificate;

  • Nishant Rana Profile Picture
    11,325 Microsoft Employee on at

    Phani, with Andrew helping, the issue will be fixed :)

  • PHANI RAJA SEKHAR TUMMALAPALLI Profile Picture
    362 on at

    Hi Andrew,

    I am now facing one more issue, please check the error message below. Do you have any idea on this?

    The one-way operation returned a non-null message with Action=''

    Thanks,

    Phani

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans