I'm trying to access CRM's WebAPI using C# and I'm wondering if there is a way of generating strong-types for the WebAPI responses similar to the way CrmSvcUtil
was used to generate strong types based on the Organizational Services
I tried to use OData v4 Client Code Generator (available from Marketplace) to generate the code and this works for the simple structures (ints, strings, decimals) however it seems to have a problem with the more complex types (e.g. Lookups)
For example making a call to /api/data/v9.0/accounts(fca0da1c-8fc3-e711-a825-000d3ae09197)?$select=_primarycontactid_value
will retrieve the Primary Contact's ID for the specified account.
The problem is that _primarycontactid_value
doesn't map to any attribute of the object generated for Account
and when the JSON results are deserialized the primarycontactid
property is left as null
Addressing Darryl's comment below; I am basing my decision to use the CRM WebAPI directly (instead of via the SDK) on the information found here where it says:
As described in Microsoft Dynamics CRM 2011 endpoint, the Dynamics CRM 2011 endpoint is deprecated in favor of the Web API. Deprecating an endpoint is a pretty big deal, especially when the programming model is as different as it is with these two endpoints. We strongly encourage developers to use the Web API for applications that connect to CRM. For plug-ins and workflow assemblies you can continue to use the SDK assemblies. In coming releases we will modify these assemblies so that they will use the Web API instead of the 2011 endpoint.
I thought the language was quite ambiguous. Microsoft say that that the SDK assemblies will be used, but also call out that they should only be used for plugins and workflows
Another link from MS stating that the CRM WebAPI should be used:
https://learn.microsoft.com/en-au/dynamics365/customer-engagement/developer/choose-development-style