我需要我的网站连接到 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/