Microsoft Dynamics CRM provides web service support that can be used to work with CRM data or metadata. CRM has the following web services:
Deployment service helps us to work with organizations, so using this web service we can create new organizations and delete or update existing organizations.
This is used to identify correct web service endpoints based on the user. Let's take an example where we have multiple CRM organizations, and we want to get a list of the organizations where current users have access; we can utilize the discovery service to find out the unique organization ID, endpoint URLs, and other details. We will be working with discovery service in a later topic.
This is used to work with CRM organization data and metadata. It has CRUD (create, retrieve, update, and delete) methods and other request and response messages. For example, if we want to create or modify any existing entity record we can use organization service methods.
Organization data service is a RESTful service that we can use to get data from CRM. We can use this service's CRUD methods to work with data, but we can't use this service to work with CRM metadata.
To work with CRM web services, we can use the following two programming models:
In early bound classes we use proxy classes generated by CrmSvcUtil.exe
. This utility is included in CRM SDK under the SDKBin
path. This utility generates classes for every entity available in the CRM system. In this programming model schema, names are used to refer to the entity and its attributes and it provides intelligence support, so we don't need to remember the entity and attribute name; as soon as we type the first letter of the entity name, it will show all entities with that name.
We can use the following syntax to generate proxy classes for CRM on-premise:
CrmSvcUtil.exe /url:http://<ServerName>/<organizationName>/XRMServices/2011/Organization.svc/out:proxyfilename.cs /username:<username> /password:<password> /domain:<domainName> /namespace:<outputNamespace> /serviceContextName:<serviceContextName>
And the following code generate a proxy for CRM online:
CrmSvcUtil.exe /url:https://orgname.api.crm.dynamics.com/XRMServices/2011/Organization.svc /out:proxyfilename.cs /username:"[email protected]" /password:"myp@ssword!"
The Organization
service URL can be obtained by navigating to Settings | Customization | Developer Resources. We are using CRM online for our demo, in case the CRM online organization
service URL is dependent on the region where your organization is hosted. You can refer https://msdn.microsoft.com/en-us/library/gg328127.aspx to get details about different CRM online regions.
We can perform the following steps to generate a proxy class for CRM online:
Bin
folder under CRM SDK and paste in the following command:CrmSvcUtil.exe /url:https://ORGName.api.crm5.dynamics.com/XRMServices/2011/Organization.svc /out:Xrm.cs /username:"[email protected]" /password:"password"
Once this file is generated we can add this file to our Visual Studio solution.
In the late bound programming model, we use a generic Entity
object to refer to our entities, which means that we can also refer to an entity that is not yet part of the CRM. In this programming model, we need to use the logical name to refer to an entity and its attribute. No support is available during code development in the case of late bound. Next is an example of using the Entity
class:
Entity AccountObj = new Entity("account");
3.19.75.133