Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

WCF service fails to connect to CRM online over trusted connection issue

Posted on by 370

Hi all,

I have hosted a WCF service on one of the ports of my IIS server. when I consume the service it fails to connect to the CRM Application. However when I browse the CRM application from the browser on the server the service is able to connect to the CRM. Do I need to install a Security Certificate on the server to make a trusted connection ???

Suggestions Please!!

Thanks in advance

Prem

*This post is locked for comments

  • Kenneth Leong Profile Picture
    Kenneth Leong 360 on at
    RE: WCF service fails to connect to CRM online over trusted connection issue

    have you figured the solution?

  • Prem27 Profile Picture
    Prem27 370 on at
    RE: WCF service fails to connect to CRM online over trusted connection issue

    sorry here , i edited one of the names in the stacktrace before putting it here but missed   editing the second one.. actually both the URL's  are same :P.  

    Anyways , yes i am able to connect using the code you mentioned above but the problem is as i have mentioned in my first query that i am only able to connect when i create a connection manually by browsing the  CRM Application on my browser; once that connection is gone service again fails to connect with the above specified stacktrace.

  • prt33k Profile Picture
    prt33k 6,907 on at
    RE: WCF service fails to connect to CRM online over trusted connection issue

    Hi Prem,

    I can see two url in error msg..

    1) ymsltest.api.crm5.dynamics.com

    2) test.api.crm5.dynamics.com

    which of these is correct?

    Usually you get this exception when protocol is wrong or url is wrong - Were you able to connect through a simple console app ... something like

    string connectionString = @"AuthType=Office365;Username=me@myorg.onmicrosoft.com;Password=mypassword;Url==https://org.crm5.dynamics.com"
    using (var con = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString))
    {
        Guid orgId = ((WhoAmIResponse)con.Execute(new WhoAmIRequest())).OrganizationId;
    }


  • Prem27 Profile Picture
    Prem27 370 on at
    RE: WCF service fails to connect to CRM online over trusted connection issue

    Thanks for your reply Prateek,

    My syntax matches with the 2nd syntax that you mentioned(Organization Service).

    Error details are as follows:

    System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: Could not establish trust relationship for the SSL/TLS secure channel with authority 'test.api.crm5.dynamics.com'. (Fault Detail is equal to An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:

    System.ServiceModel.Security.SecurityNegotiationException: Could not establish trust relationship for the SSL/TLS secure channel with authority 'ymsltest.api.crm5.dynamics.com'. ----> System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ----> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

       at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)

       at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)

       at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)

       at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncReques...).

     

  • prt33k Profile Picture
    prt33k 6,907 on at
    RE: WCF service fails to connect to CRM online over trusted connection issue

    CrmServiceClient can be used for Organization service as well as webAPI.

    Does you syntax look like this:

    CrmServiceClient crmSvc = new CrmServiceClient("<UserName>", CrmServiceClient.MakeSecureString("<Password>"), "<CrmRegion>", "<OrgName>", useUniqueInstance:false, <orgDetail>,

                     <userIdentifier>, <clientId>, <redirectUri>, <tokenCachePath>, <externalOrgWebProxyClient>, PromptBehavior.Auto);

    Or follow this:

    CrmServiceClient crmSvc = new CrmServiceClient("<UserName>", CrmServiceClient.MakeSecureString("<Password>"), "<CrmRegion>", "<OrgName>", useUniqueInstance:false, useSsl:false, <orgDetail>, isOffice365:true);

    In case its the first syntax then you need to register you app on Azure as guided in the link.

    If it is the second format then please share the extact error message that you are receiving.

    Thanks,

    PS

  • Prem27 Profile Picture
    Prem27 370 on at
    RE: WCF service fails to connect to CRM online over trusted connection issue

    Hi,

    I am using  CrmServiceClient to connect to CRM.

  • Suggested answer
    prt33k Profile Picture
    prt33k 6,907 on at
    RE: WCF service fails to connect to CRM online over trusted connection issue

    How are you trying to connect to CRM? Using Organization service or using webAPI?

    If you are using webAPI then you need to register your application on Azure first so that authentication can happen.

    This might be helpful: msdn.microsoft.com/.../mt595797.aspx

    Do share the error message if this doesnt work.

    Thanks,

    PS

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans