首页 > 解决方案 > 将连接传递到 Dynamics 365 CRM 后获取服务

问题描述

我一直在发布有关 Dynamics 365 集成的问题,我将简要解释我面临的问题。我用来连接的代码是这个

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
    CrmServiceClient conn = new CrmServiceClient(new NetworkCredential("<username>", "<Password>", "<domain>"), Microsoft.Xrm.Tooling.Connector.AuthenticationType.IFD, "<url>", "<port>", "<OrgName>");
    _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
            // Retrieve the version of Microsoft Dynamics CRM.
RetrieveVersionRequest versionRequest = new RetrieveVersionRequest();
    RetrieveVersionResponse versionResponse = (RetrieveVersionResponse)_orgService.Execute(versionRequest);
    Console.WriteLine("Microsoft Dynamics CRM version {0}.", versionResponse.Version);

凭据不会返回服务请求,这是我收到的错误日志。

Inner Exception Level 3 :
 Source  : System
 Method  : Receive
 Date    : 26/09/2018
 Time    : 11:19:51 AM
 Error   : An existing connection was forcibly closed by the remote host
 Stack Trace     : at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 
 offset, Int32 size, SocketFlags socketFlags)
 at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)

 Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : Unable to Login to Dynamics CRM
 Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationWebProxyClient is null
 Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationServiceProxy is null
The application terminated with an error.

Microsoft 提供的使用工具连接器的示例程序都不起作用。我不能使用 OrganizationClient 连接,因为集成不会使用 Microsoft.SDK.Client.dll 运行。我被困在这里,我想知道这是否是托管 CRM 的问题。对此的任何帮助将不胜感激。

标签: c#dynamics-crmdynamics-365

解决方案


您需要在连接字符串中包含 AuthType=Office365。

用下面的这两行替换代码的第 2 行。在哪里

  • {url} 是您的 D365 实例 URL
  • {username} 是您的 D365 用户名(尝试:用户名或域\用户名)
  • {password} 是您的 D365 密码
  • {hru} 是您的 ADFS 主域 url
  • {domain} 是您的 AD 域

    string conStr = $"AuthType=IFD;HomeRealmUri={hru};Domain={domain};Url={url};Username={username};Password={pass}"; CrmServiceClient 服务 = 新 CrmServiceClient(conStr);


推荐阅读