【问题标题】:The value 'Xrm.XrmServiceContext, Xrm' is not recognized as a valid type or is not of the type 'Microsoft.Xrm.Sdk.Client.OrganizationServiceContext'值“Xrm.XrmServiceContext,Xrm”未被识别为有效类型或不是“Microsoft.Xrm.Sdk.Client.OrganizationServiceContext”类型
【发布时间】:2013-05-11 04:54:57
【问题描述】:

我正在尝试连接到 MS Dynamics 2011 Online。在我的代码的 using xrm 部分,我收到此错误:

值“Xrm.XrmServiceContext, Xrm”未被识别为有效类型或不是“Microsoft.Xrm.Sdk.Client.OrganizationServiceContext”类型。

这是我的代码:

        var contextName = "Xrm";
        using (var xrm = CrmConfigurationManager.CreateContext(contextName) as XrmServiceContext)
        {


            WriteExampleContacts(xrm);

            //Create a new contact called Allison Brown.
            var allisonBrown = new Xrm.Contact
            {
                FirstName = "Allison",
                LastName = "Brown",
                Address1_Line1 = "23 Market St.",
                Address1_City = "Sammamish",
                Address1_StateOrProvince = "MT",
                Address1_PostalCode = "99999",
                Telephone1 = "12345678",
                EMailAddress1 = "allison.brown@example.com"
            };

            xrm.AddObject(allisonBrown);
            xrm.SaveChanges();

            WriteExampleContacts(xrm);
        }

App.config:

  <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
  <section name="microsoft.xrm.client" type="Microsoft.Xrm.Client.Configuration.CrmSection, Microsoft.Xrm.Client"/>
  </configSections>

  <connectionStrings>
    <add name="Xrm"     
connectionString="Url=https://MYORG.crm.dynamics.com/XRMServices"/>
  </connectionStrings>

<microsoft.xrm.client>
<contexts>
  <add name="Xrm" type="Xrm.XrmServiceContext, Xrm"/>
</contexts>
</microsoft.xrm.client>
</configuration>

Xrm.XrmServiceContext 是我的实际 XrmServiceContext 名称。它保存在我的控制台应用程序的 Xrm.cs 文件中。

【问题讨论】:

    标签: dynamics-crm-2011 microsoft-dynamics


    【解决方案1】:

    只需使用简化的连接即可。

    您需要参考Microsoft.Xrm.Sdk.ClientMicrosoft.Xrm.Client.Services

    CrmConnection crmConnection = CrmConnection.Parse("Url=https://XXX.crm4.dynamics.com; Username=user@domain.onmicrosoft.com; Password=passwordhere; DeviceID=contoso-ba9f6b7b2e6d; DevicePassword=passcode;");
    OrganizationService service = new OrganizationService(crmConnection);
    
    XrmServiceContext context = new XrmServiceContext(service);
    
    var allisonBrown = new Xrm.Contact
                {
                    FirstName = "Allison",
                    LastName = "Brown",
                    Address1_Line1 = "23 Market St.",
                    Address1_City = "Sammamish",
                    Address1_StateOrProvince = "MT",
                    Address1_PostalCode = "99999",
                    Telephone1 = "12345678",
                    EMailAddress1 = "allison.brown@example.com"
                };
    
    context.AddObject(allisonBrown);
    context.SaveChanges();
    

    【讨论】:

    • 谢谢!我不需要crm4中的4,因为我使用的是在线版。
    • crm、crm4 或 crm5 取决于托管您的 crm 在线环境的区域(美国、欧洲、中东和非洲、亚太地区)。
    • 在哪里可以找到 Microsoft.Xrm.Client.Services ?
    • @AllWorkNoPlay DLL 位于 Dynamics CRM SDK 中。从此处选择您的版本:crmanswers.net/p/resources-for-crm-developers.html
    • 关于Microsoft.Xrm.Client.Services你需要在你的代码顶部做using Microsoft.Xrm.Client.Services;
    猜你喜欢
    • 2018-02-28
    • 2021-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多