microsoft / PowerApps-Samples

Sample code for Power Apps, including Dataverse, model-driven apps, canvas apps, Power Apps component framework, portals, and AI Builder.
https://docs.microsoft.com/powerapps
MIT License
1.48k stars 1.68k forks source link

System.ServiceModel.Security.MessageSecurityException: The HTTP request was forbidden with client authentication scheme 'Anonymous'. #99

Closed HASSEN-MEDDEB-ATOS closed 4 years ago

HASSEN-MEDDEB-ATOS commented 4 years ago

Hello,

I try to connect to Dynamics using client secret, i have created an application registartion, i have added secret client this is my code

public static CdsServiceClient InitCRMConnection()
            {

                    try
                    {

                        string connectionstring = ConfigurationManager.ConnectionStrings["connectionVSMP"].ConnectionString;

                        sp = new CdsServiceClient(connectionstring);

                    }

                     catch (Exception ex)
                    {
                                LogHelper.Writer("Erreur lors de la connexion au crm, Message de l'erreur : " + Environment.NewLine + ex.ToString());
                    }

               return sp;
            }
<configuration>
  <connectionStrings>
    <add name="connectionVSMP" connectionString="url=*********;ClientId=**********;ClientSecret=*******;AuthType=ClientSecret" />
  </connectionStrings>
</configuration>

Microsoft.Powerplatform.Cds.Client.Utils.CdsConnectionException: Failed to connect to Common Data Service ---> System.ServiceModel.Security.MessageSecurityException: The HTTP request was forbidden with client authentication scheme 'Anonymous'. at Microsoft.Powerplatform.Cds.Client.CdsConnectionService.InitCdsService() at Microsoft.Powerplatform.Cds.Client.CdsConnectionService.GetCachedCDSService(CdsConnectionService& ConnectionObject) at Microsoft.Powerplatform.Cds.Client.CdsConnectionService.IntilizeService(CdsConnectionService& ConnectionObject) at Microsoft.Powerplatform.Cds.Client.CdsConnectionService.DoLogin(CdsConnectionService& ConnectionObject) at Microsoft.Powerplatform.Cds.Client.CdsServiceClient.CreateCdsServiceConnection(Object externalOrgServiceProxy, AuthenticationType requestedAuthType, String hostName, String port, String orgName, NetworkCredential credential, String userId, SecureString password, String domain, String Geo, String claimsHomeRealm, Boolean useSsl, Boolean useUniqueInstance, OrganizationDetail orgDetail, UserIdentifier user, String clientId, Uri redirectUri, PromptBehavior promptBehavior, String tokenCachePath, OrganizationWebProxyClient externalOrgWebProxyClient, String certificateThumbPrint, StoreName certificateStoreName, X509Certificate2 certificate, Uri instanceUrl, Boolean isCloned, Boolean useDefaultCreds) --- End of inner exception stack trace --- at Microsoft.Powerplatform.Cds.Client.CdsServiceClient.CreateCdsServiceConnection(Object externalOrgServiceProxy, AuthenticationType requestedAuthType, String hostName, String port, String orgName, NetworkCredential credential, String userId, SecureString password, String domain, String Geo, String claimsHomeRealm, Boolean useSsl, Boolean useUniqueInstance, OrganizationDetail orgDetail, UserIdentifier user, String clientId, Uri redirectUri, PromptBehavior promptBehavior, String tokenCachePath, OrganizationWebProxyClient externalOrgWebProxyClient, String certificateThumbPrint, StoreName certificateStoreName, X509Certificate2 certificate, Uri instanceUrl, Boolean isCloned, Boolean useDefaultCreds) at Microsoft.Powerplatform.Cds.Client.CdsServiceClient.ConnectToCdsService(String cdsConnectionString) at Microsoft.Powerplatform.Cds.Client.CdsServiceClient..ctor(String cdsConnectionString) i apperciate any help

Thank you

Cordially

HASSEN-MEDDEB-ATOS commented 4 years ago

@MattB-msft any suggestion please Cordially

phecke commented 4 years ago

@HASSEN-MEDDEB-ATOS This is not the correct place to post this issue as there are no samples here related to the new (alpha) CDS service client. For assistance with this problem, go to the NuGet page for the package that contains the assembly/class in question and select the 'Contact owners' link on that page. That should get you a response. The owner is crmsdk.