3

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

jasonscript
  • 6,039
  • 3
  • 28
  • 43
  • What are you wanting to use the WebApi over the SDK calls? It has been said multiple times that the SDK calls will be internally replaced with the WebApi calls... – Daryl Dec 15 '17 at 13:39
  • @Daryl I've added an edit where I try to answer your question. The short answer is that I found the documentation from Microsoft was pretty ambiguous – jasonscript Dec 18 '17 at 01:28
  • @Daryl more documentation from MS stating we should use the WebApi – jasonscript Jan 03 '18 at 06:17
  • It states you should use the tooling assemblies (which are built in the SDK) if you're doing development on Windows, are you not? – Daryl Jan 03 '18 at 11:43

1 Answers1

0

The _primarycontactid_value property won't map to a reference to class for Contact entity since it represents structural property of type Edm.Guid. The property that represents navigation property of type Contact is Primarycontactid. Copying the property definitions from generated client SDK classes below:

public global::System.Nullable<global::System.Guid> _primarycontactid_value    
public global::ODataV4Sdk.Contact Primarycontactid

Microsoft's OData client library might have in-built support for expanding navigation properties and but it is not possible to link or unlink records. There is no example present in OData library documentation: http://odata.github.io/odata.net/#04-01-basic-crud-operations.

On other hand, Simple.Odata.Client (https://github.com/object/Simple.OData.Client/wiki) provides typed syntax and supports linking operations but as per my knowledge, it does not have the tooling support. The classes are required to be created manually. The class-creation work can be avoided with untyped syntax but of course, we will not get the Intellisense to speed up coding and it is possible that spelling mistakes are not uncovered until runtime.

Jatin Sanghvi
  • 1,928
  • 1
  • 22
  • 33
  • The solution I'm working on is a mixture of solutions from different vendors, so the naming conventions are not consistent so spelling errors is what I am running into frequently. Thanks for the answer, but I'm a bit disappointed that the CRM WebApi currently seems like a step back from the features that were available previously – jasonscript Dec 14 '17 at 00:46