c# - 连接到 CRM

标签 c# asp.net dotnetnuke crm web-config

我需要我的网站连接到 CRM 这是我的代码

        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");
        }

这是在我的 web.config 中

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

它给我这个错误信息:

"A critical error has occurred. Unable to connect with CRM server. The caller was not authenticated by the service."

最佳答案

你应该使用 ►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's not mandatory in this case -->

如果使用 IFD 或在线进行内部部署,则应该是

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

关于c# - 连接到 CRM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24115190/

相关文章:

asp.net - asp.net 中的 subsonic 是否是一个好方法?

c# - 如何记录系统用户所做的更改?

sql - DotNetNuke,用户帐户 “sa” 的指定密码无效

java - 仅在使用 UNITY3d 构建的 Android 应用程序中实例化 SoapService 时出现 ArgumentException

c# - 您可以命名 Func<T> 类型的参数吗?

c# - .Net 线程.CurrentPrincipal

c# - 如何通过父控件中的事件为子控件设置动画? - 可重复使用的方式

c# - Global.asx 和 CSS 之间的冲突

asp.net - DotNetNuke 网站迁移到 Azure 失败,出现 nx 域 DNS 错误

asp.net - Visual Studio 2012 中的 DotNetNuke 网站项目