06.12.2012, 21:11 | #1 |
Участник
|
Danny Varghese: Sample CRM 2011 Retrieve and Retrieve Multiple
Источник: http://varghesedanny.com/2012/12/06/...ieve-multiple/
============== Thank you to all who have been reading my blog articles and have commented and sent personal messages. It means a lot to me to know some of my content might be helping. A common request I get is to post sample code on some basic operations using web services. I’ll try to do that in the upcoming articles. For those of you that are seasoned CRM developers, this might be redundant and I apologize! The method GetCRMService() is a private helper method used to retrieve an instance of the CRM web service using on-premise AD authentication. The code to authenticate for IFD and even for the Office 365 credentials are different and will be posted in a later article. private IOrganizationService GetCRMService(){ // Initialize credentials for service authentication ClientCredentials credentials = new ClientCredentials(); credentials.Windows.ClientCredential = new System.Net.NetworkCredential("username", "password", "domain"); // Configure the org uri with the organization service url Uri organizationUri = new Uri("http://servername/orgname/XRMServices/2011/Organization.svc"); IServiceConfiguration config = ServiceConfigurationFactory.CreateConfiguration(organizationUri); // The using statement assures that the service proxy will be properly disposed. using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(config, credentials)) { return serviceProxy; } }An example of retrieve a single record, given the record id is below: public Entity RetrieveRecord(string entityName, Guid recordId, ColumnSet columns){ return GetCRMService().Retrieve(entityName, recordId, columns);}An example of retrieving multiple records is below: public IEnumerable RetrieveRecords(string entityName, ColumnSet columns){ QueryExpression query = new QueryExpression { EntityName = entityName, ColumnSet = columns, Criteria = new FilterExpression { Conditions = { new ConditionExpression { AttributeName = "attributeName", Operator = ConditionOperator.Equal, Values = {"attributeValue"} } } }; } return GetCRMService().RetrieveMultiple(query).Entities; } Источник: http://varghesedanny.com/2012/12/06/...ieve-multiple/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
|
|