I have been posting my issues around Dynamics 365 integration and I will briefly explain the issues I am facing.The code I am using to connect is this
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);
The credentials wouldn't return the service request and this is the error log I receive.
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.
None of the sample programs from Microsoft that use a tooling connector wont work. I cannot use OrganizationClient connection as the integrations wont run using Microsoft.SDK.Client.dll. I am pretty stuck here and I wonder if it is an issue with the hosted CRM. Any help on this would be so appreciated.
You need to include AuthType=Office365 in your connection string.
Replace line 2 of your code with this two lines below. Where
{domain} is your AD domain
string conStr = $"AuthType=IFD;HomeRealmUri={hru};Domain={domain};Url={url};Username={username};Password={pass}"; CrmServiceClient service = new CrmServiceClient(conStr);
I have rarely needed to set the security protocol, so you could try skipping setting the security protocol and use a simple connection string in the CrmServiceClient
constructor.
First, set the connection string according to your version:
On-premise IFD before CRM 2016:
var connectionString = "Url=https://contoso.litware.com; Username=someone@litware.com; Password=password; AuthType=IFD;"
On-premise IFD for CRM 2016 and later (v8.0+)
var connectionString = "ServiceUri=https://contoso.litware.com/contoso; Domain=contoso; Username=contoso\administrator; Password=password; AuthType=IFD; LoginPrompt=Never;"
Then pass it into the constructor:
var svc = new CrmServiceClient(connectionString);
Then you can check if the service is ready:
if(!svc.IsReady) { throw new Exception("Service not ready");}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.