2013-05-10 35 views
1

我正在尝试连接到MS Dynamics 2011 Online。在我的代码中使用xrm部分,我收到此错误:值'Xrm.XrmServiceContext,Xrm'不被识别为有效类型或不是类型'Microsoft.Xrm.Sdk.Client.OrganizationServiceContext'

值'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 = "[email protected]" 
      }; 

      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文件中。

回答

2

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

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

CrmConnection crmConnection = CrmConnection.Parse("Url=https://XXX.crm4.dynamics.com; [email protected]; 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 = "[email protected]" 
      }; 

context.AddObject(allisonBrown); 
context.SaveChanges(); 
+0

谢谢!我不需要crm4中的4,因为我使用的是在线版本。 – 2013-05-10 20:58:19

+2

crm,crm4或crm5取决于您的crm在线环境中的哪个区域(美国,欧洲,中东和非洲)。 – 2013-05-10 21:29:32

+0

我在哪里可以找到Microsoft.Xrm.Client.Services? – AllWorkNoPlay 2014-12-10 10:21:49

相关问题