首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >值'Xrm.XrmServiceContext,Xrm‘不能识别为有效类型,也不属于Xrm.XrmServiceContext类型

值'Xrm.XrmServiceContext,Xrm‘不能识别为有效类型,也不属于Xrm.XrmServiceContext类型
EN

Stack Overflow用户
提问于 2013-05-10 20:05:38
回答 1查看 5.5K关注 0票数 1

我正在尝试连接到MSDynamics2011Online。在我的代码中使用xrm部分时,我会收到以下错误:

值‘'Microsoft.Xrm.Sdk.Client.OrganizationServiceContext'.,Xrm’不能识别为有效类型,也不能识别为类型

这是我的代码:

代码语言:javascript
复制
        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:

代码语言:javascript
复制
  <?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文件中。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-10 20:54:57

只需使用简化的连接。

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

代码语言:javascript
复制
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();
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16490042

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档