Search code examples
.netdynamics-crm-2011dynamics-crm-4

using WebServices vs using Dynamic Entities in Microsoft CRM 4.0


I'm on a debate with a colleague regarding using webservices in a plugin or a workflow

he says using dynamic entites is the best practice as suggested by microsoft, as web-service require authentication.

I think using the wsdl and the strong typed entities is cleaner and less error prone, and the authentication delay is negligable

also, we are planning on updating to CRM 2011

so, which one of us is right ?


Solution

  • Both strongly typed and dynamic entities use web services, which both require authentication, so theres no real difference there.

    In terms of upgrade to Crm 2011, the web services have changed in 2011, so if you wanted to re-code you could, but both would have to be re-coded. Or you could just continue using the Crm 4 webservices and not re-code. So again no real difference.

    I couldnt find anything from Microsoft saying they prefer Dynamic Entities. In Best Practices for Developing with Microsoft Dynamics CRM 2011 they actually say to use both depending your situation.

    Use the Entity class when your code must work on entities and attributes that are not known at the time the code is written. However, this flexibility has a disadvantage because you cannot verify entity and attribute names at compile time. If your entities are already defined at code time, you should use the early-bound types that you can generate by using the CrmSvcUtil tool. For more information, see Use the Early Bound Entity Classes in Code.

    I think this mostly comes down to style and preference (no one can be right) - personally I prefer Dynamic Entities.

    Strongly Typed - Pros:

    • Intellisense
    • Design\Compile time validation
    • You dont have to check Crm for all the entity, field and relationships names
    • The compiled executable contains the code necessary to invoke the types’ properties, methods, and events

    Strongly Typed - Cons:

    • You have to generate the WSDL (and keep regenerating it everytime Crm changes)
    • The generated classes dont pass code analysis last time I checked
    • It can be a bit 'heavy handed', e.g. to create a new record with dynamic entities is generally a couple of lines. Having to generate hundreds of strongly typed classes to write a couple of lines seems like an overkill.