2010-07-13 63 views
1

这里是我的代码示例...创建联系人和更新的自定义字段MSCRM 4

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using ProjectName.CrmSdk; 

//The CrmSdk ref is to the webservice url. 

      //ServerName and OrgName are setup in code but not included. 
      //standard CRM service setup 
      CrmSdk.CrmAuthenticationToken token = new CrmSdk.CrmAuthenticationToken(); 
      token.AuthenticationType = 0; //AD on premise 
      token.OrganizationName = orgName.ToString(); 
      CrmService service = new CrmService(); 
      service.Url = "http://" + serverName.ToString() + "/mscrmservices/2007/crmservice.asmx"; 
      service.CrmAuthenticationTokenValue = token; 
      service.Credentials = System.Net.CredentialCache.DefaultCredentials; 


      contact c = new contact(); 

      c.firstname = "joe"; 
      c.lastname = "Smack"; 
      // I can not find or access this custom field when I go to create a contact. 
      c.new_customField = "Red Car"; 

现在的问题很简单,我不能访问任何我已添加到联系人对象的自定义字段。我试图从C#创建一个联系人,并且我创建的所有基本字段都不是自定义字段。

谢谢

回答

3

您正在使用自动生成的服务参考。每当您对CRM中的实体进行(并发布)更改时,请更新Visual Studio中的服务参考。

+1

为了避免不断更新服务引用,您也可以使用DynamicEntity对象并以这种方式进行更新。 – Matt 2010-07-13 11:38:31

+1

事实上..缺点就是你失去了强大的打字能力......但是好处是灵活性更大,并且能够抽象出在普通DynamicEntity上运行的某些功能。 – PjL 2010-07-13 13:25:53

0

右键单击解决方案资源管理器中Web服务下的引用,然后单击“更新Web引用”。自定义选项现在应该可用。