问题
I am not able to connect to Organization service even with I have used correct credentials in CRM dynamics - C# I am able to login from dynamics crm site with same credential. I am using Microsoft.crm.SDK version 9 and also getting response code 200 with HttpClient as shown below.
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(webApiUrl);
client.DefaultRequestHeaders.Authorization = authHeader;
var response = client.GetAsync("WhoAmI").Result;
}
BUT the problem is with Organization service, It is giving me message security exception. Can you please help me with this, I have tried many solutions from internet but not succeed. Please find attached photos for exception detail, and feel free if you need more information.
Connection string I am using
Error from organization service
Inner exception
回答1:
If I understand your question correct, you are using dynamics 365 version 9.0 online and you are connecting to dynamics using webapi.
You are bit confused here. There are 2 ways from using c# you can connect to crm. 1. Using webapi. Here you need authentication token and so on. 2. Dynamics 365 (crm assemblies) here you do not need authentication token rather username and password
And you want webapi so in your case no need for organizationservice, once you are connected with your authentication header and so on you can call webapi url for create/retrieve and so on and get your work done.
Some examples here for webapi
https://www.inogic.com/blog/2016/04/set-values-of-all-data-types-using-web-api-in-dynamics-crm-through-c/
https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/web-api-samples-csharp
https://rajeevpentyala.com/tag/web-api/
Using organization service example of console app
I am not sure where you will be firing your c# but below example of console app will help you
https://www.google.com/amp/s/arunpotti.wordpress.com/2018/02/03/step-by-step-to-connect-dynamics-365-crm-online-v9-x-using-c-console-application/amp/
Edit:
You could also you plugin from XRMToolBox. It is called codenow This will definitely solve your issue.
来源:https://stackoverflow.com/questions/60012450/not-able-to-connect-to-organization-service-even-with-used-correct-credentials-i