在CRM 2011中,您不會像在CRM 4中那樣添加對web服務的引用。如果您想要早綁定的實體類,那麼您將必須使用crmsvcutil.exe生成此類。如果您打算使用LINQ查詢您的CRM數據,請添加/ serviceContextName:contextname,並在代碼文件中生成OrganizationServiceContext。
如果你不關心早期綁定的實體類,那麼你可以使用實體類。在2011年,您將使用CRM 4中稱爲DynamicEntity的實體類。
爲了使用CRM 2011做任何事情,您必須添加一些對項目的引用,您會在bin文件夾中找到它們有sdk。
您將始終添加對Microsoft.Xrm.Sdk的引用。如果您將使用早期綁定,則還需要對Microsoft.Crm.Sdk.Proxy的引用。 從標準.Net庫中,您將必須添加對System.ServiceModel和System.Runtime.Serialization的引用
要連接到CRM 2011,您將使用OrganizationServiceProxy。
var organizationUri = new Uri("http://<servername>/<organizationname>/XRMServices/2011/Organization.svc");
var credentials = new ClientCredentials();
var serviceProxy = new OrganizationServiceProxy(organizationUri, null, credentials, null);
// If you use early bound entity classes, you have to include the line below. Not needed on late bound
serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
然後通過使用已經創建的serviceproxy,我可以開始使用CRM數據。 創建帳戶:
var account = new Account();
account.Name = "Testing";
serviceProxy.Create(account);
一些鏈接獲得進一步的閱讀:
DiscoveryService
Using the IOrganizationService
Using Organization Service Context
感謝偉大的答案! :) – 2012-07-24 14:04:31