添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

IOrganizationService organizationService = null;
try
{
ClientCredentials clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = "......onmicrosoft.com";
clientCredentials.UserName.Password = "password";
// For Dynamics 365 Customer Engagement V9.X, set Security Protocol as TLS12
// ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

organizationService = (IOrganizationService)new OrganizationServiceProxy(new Uri(" ">-------.api.crm8.dynamics.com/.../Organization.svc"),
null, clientCredentials, null);
if (organizationService != null)
{
// Guid userid = ((WhoAmIResponse)organizationService.Execute(new WhoAmIRequest())).OrganizationId;
Guid userid = ((WhoAmIResponse)organizationService.Execute(new WhoAmIRequest())).UserId;

if (userid != Guid.Empty)
{
Console.WriteLine("Connection Successful!...");
}

}
else
{
Console.WriteLine("Failed to Established Connection!!!");
}

Use of the WS-Trust authentication security protocol when connecting to Microsoft Dataverse is no longer recommended and has been deprecated.  You need to switch over to using an OAuth based connection string. Please refer to the sample code below:

using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Tooling.Connector;
using System;
namespace Dynamics365ConsoleApp
    class Program
        static void Main(string[] args)
            CrmServiceClient crmSvc = getOrganizationService();
            Console.ReadLine();
        public static CrmServiceClient getOrganizationService()
            CrmServiceClient crmSvc = null;
            String connString = "AuthType=OAuth;[email protected];Password=xxxxxx;Url=https://xxxxxx.crm4.dynamics.com;AppId=51f81489-12ee-4a9e-aaae-a2591f45987d;RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97;TokenCacheStorePath=c:\\MyTokenCache;LoginPrompt=Auto";
                crmSvc = new CrmServiceClient(connString);
                if (crmSvc != null)
                    var whoAmIResponse = ((WhoAmIResponse)crmSvc.Execute(new WhoAmIRequest()));
                    if (whoAmIResponse != null)
                        Console.WriteLine("Connection OK....");
                        Console.WriteLine(whoAmIResponse.UserId);
                        Console.WriteLine("Connection KO....");
            catch (Exception e)
                Console.WriteLine("ERROR...");
                Console.WriteLine(e.Message);
            return crmSvc;

Please note: The AppId and RedirectUri provided above are examples of working application registration values. These values work everywhere online services are deployed. However, they are provided here as examples and you are encouraged to create your own application registration in Azure Active Directory (AAD) for applications running in your tenant.

Documentation: https://docs.microsoft.com/en-us/powerapps/developer/data-platform/authenticate-office365-deprecation

Subscribe to

Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.