Thursday, August 16, 2012

CrmSvcUtil Tutorial

First, what is this handy utility?

The crmsvcutil is a tool to help generate the early bound entities while developing projects for your CRM2011 environment.  The primary advantages I find of using this are

  • Enabling intellisense for your crm entities
  • Allows you to easily use the CRM2011 API rather than being a bad person and updating the database directly.  I know it's tempting to do, but take it from a guy who has had to go back and rewrite whole applications, just don't.
Disadvantages:
  • Regenerating classes to keep up with changes the target CRM2011 environment.  However with this guide you shouldn't have much trouble doing this quickly if need be.

_________________________________________________________________________________
You're preflight checklist....


  1. Do you have WIF (Windows Identity Foundation) installed?  If not, go here.
  2. Do you have the CRM2011 sdk installed?  If not, go here.
  3. (Optional?) Do you have an environment to compile the tool?  I've only ever used VS2010 to do this, I'm sure later versions will work as well.  I had to compile this tool once or twice for a client but I think it comes compiled already with the CRM2011 sdk.  It can be found in the /bin folder where you extract the SDK files.  You will also need this to compile the deviceregistration tool if needed.
_________________________________________________________________________________
Have you got everything you need?  Great!  Now let's get on to some of the steps you may need to take before executing this utility.  Let's answer a question or two.

  • Are you developing for a CRMOnline environment?  Then you will need to run the deviceregistration tool.
    • First compile the tool (in the \tools\deviceregistration directory where you extracted the SDK files)
    • Now open you command prompt and navigate to that directory, use this command line
      • deviceregistration.exe /operation:Register
    • Copy the device id and device password given, you will need these later.
  • Do you want a C# or VB output?  The tool defaults to C#.
Now that we have those common questions out of the way using the tool is pretty straightforward.  Just navigate a command prompt to the directory where the tool is located (usually /bin in the sdk folder) and follow this quick template for an IFD/Local CRM environment.

CrmSvcUtil.exe /url:"http://yourCRMAddress/CRM/XRMServices/2011/Organization.svc" /out:"GeneratedEntities.cs" /servicecontextName:"yourServiceContextName" /username:"domain\username" /password:"******" /namespace:"XrmEntities" 

A more extensive list of parameters can be found here.

Obviously you will need to know the domain name and username you wish to use, this user has to be able to login to CRM.  I usually have some sort of high privileged developer account within any CRM environment I am working on.

The ServiceContextName can be found in your CRM environment by going to the settings page (bottom left) within CRM , then navigating to Customization on the left hand menu, click on Developer Resources and use the "Organization Unique Name" here.

If all is well you should have a new file to include in your development project that will make your life much easier by letting you use all the tools of your IDE with this new class file.

1 comment: