2012-10-17 25 views
3

我已經設置了一個測試Dynamics CRM 2011服務器。我已經使用CrmSvcUtil爲Dynamics CRM 2011生成了早期綁定的實體類 - 現在是什麼?

我已經使用SDK的CrmSvcUtil實用程序來生成早期綁定的實體類(例如mycrm.cs)。

我在Visual Studio中創建了一個新項目,並添加了對Microsoft.CRM.SDK.Proxy,Microsoft.Xrm.Sdk和System.Runtime.Serialization的引用。

我還將mycrm.cs文件作爲現有文件添加到我的項目中。

現在呢?

我知道,我知道...閱讀SDK。我試過:如果必須

Using the Early Bound Entity Classes in Code

Using the Early Bound Entity Classes for Create, Update, Delete

Create Early Bound Entity Classes with the Code Generation Tool (CrmSvcUtil.exe)

叫我白癡 - 我敢肯定,這些文章可能包含的信息。我需要,但我沒有看到它。幫幫我!

+1

這是什麼問題?你想幹什麼?所有與Dynamics基於其服務的通信,您所能做的就是從解決方案中調用它的方法。擴展CRM的另一種方式是使用自定義實體或組或任何其他方式從UI創建包。 – user854301

+0

我想對我的CRM執行CRUD操作。我有一個獨立的互聯網應用程序,我想同步信息。從這個應用程序。進入Dynamics CRM。 – davemackey

+1

您是否已連接到* OrganizationService *?你能從這項服務中獲得任何東西嗎? – user854301

回答

7

首先,你需要連接到CRM Web服務:

OrganizationServiceProxy orgserv; 
ClientCredentials clientCreds = new ClientCredentials(); 
ClientCredentials devCreds = new ClientCredentials(); 


clientCreds.Windows.ClientCredential.UserName = "user"; 
clientCreds.Windows.ClientCredential.Password = "[email protected]$$w0rd"; 
clientCreds.Windows.ClientCredential.Domain = "myDomain"; 
IServiceConfiguration<IOrganizationService> orgConfigInfo = 
      ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(new Uri("https://myCRMServer/myOrg/XRMServices/2011/Organization.svc")); 

orgserv = new OrganizationServiceProxy(orgConfigInfo, clientCreds); 
orgserv.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); 

之後,你要使用你的XrmServiceContext,否則你怎麼會在這裏命名爲:

CrmSvcUtil.exe /url:http://servername/organizationname/XRMServices/2011/Organization.svc /out:.cs/username:/ password:/ domain: /namespace:/ serviceContextName:XrmServiceContext

然後你就可以用CRUD的例子從link you posted更新開始接觸的:)

例子:

using(var context = new XrmServiceContext(orgserv)) 
{ 
    Contact con = context.contactSet.FirstOrDefault(c => c.Name == "Test Contact"); 
    if(con != null) 
    { 
     con.City = "NY"; 

     context.UpdateObject(con); 
     context.SaveChanges(); 
    } 
} 

希望它能幫助:)

相關問題