Connect to CRM

I need my site to connect to CRM, this is my code

        var organizationUri = new Uri(ConfigurationManager.AppSettings["CRMServerUrl"]);

        //Client credentials
        var credentials = new ClientCredentials();
        credentials.UserName.UserName = @"<user>";
        credentials.UserName.Password = "<password>";
        // Use the Microsoft Dynamics CRM Online connection string from the web.config file named "CrmConnectionStr".
        using (OrganizationServiceProxy _service = new OrganizationServiceProxy(organizationUri, null, credentials, null))
        {
            Response.Write("Connected");
        }

and this is in my web.config

 <add key="CRMServerUrl" value="http://XXXXX/XRMServices/2011/Organization.svc" />
<add key="username" value="<user>" />
<add key="password" value="<password>" />

he gives me this error message:

"A fatal error has occurred. Could not connect to the CRM server. The caller was not authenticated by the service.

+4
source share
4 answers

use these assemblies in your project

using Microsoft.Xrm.Client;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Client.Services;

create an orgnuisation service

string connectionString = "Url=https://your_orgnisation.crm5.dynamics.com; Username=user_name; Password=your_password;";
  CrmConnection connection = CrmConnection.Parse(connectionString);
 OrganizationService organisationservice = new OrganizationService(connection);

AND YOU DID!

INCORRECT FORMAT FOR IMPORT System.Runtime.serialization. enter code here

+5
source

By looking at your code, you are not using username and password  Change below lines:

    //Client credentials
    var credentials = new ClientCredentials();
    credentials.UserName.UserName =ConfigurationManager.AppSettings["username"].toString();
    credentials.UserName.Password =ConfigurationManager.AppSettings["password"].toString();

try the following: Default Credentials are used,using Windows Authentication

ClientCredentials Credentials = new ClientCredentials();
Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

// This URL needs to be updated to match the server name and organization for the environment.

Uri OrganizationUri = new Uri("http://XXXXX/XRMServices/2011/Organization.svc");
Uri HomeRealmUri = null;
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))
  {          
   IOrganizationService service = (IOrganizationService)serviceProxy;
  }
+4
source

►Simplified Connection, ►Microsoft. Xrm.Client.CrmConnection .

:

1) .config

<connectionStrings>
  <add name="CrmConnStr" connectionString="!SEE EBELOW!"/>
</connectionStrings>

2) :

// parameter is the name of the connection string
// NOTE: These "setup" declarations are slow, reuse them as much as possibile
var connection = new CrmConnection("CrmConnStr");

var service = new OrganizationService(connection);
var context = new CrmOrganizationServiceContext(connection);

, On-Premise WITHOUT IFD

"Url=http[s]://serverurl/organization; Domain=DOMAIN; Username=USERNAME; Password=PASSWORD"
<!-- https is always nice, but it not mandatory in this case -->

On-Premise WITH IFD Online

"Url=https://org.server.url; Username=USERNAME; Password=PASSWORD"
<!-- https is of course mandatory here -->
<!-- 'DOMAIN=...' part is not needed because of ADFS -->
+4

Source: https://habr.com/ru/post/1543827/


All Articles