Download Microsoft CRM 2011 SDK - SDK voorpagina - CRM Performance - CRM Hosting
Heeft u vragen? Bel ons op 030 800 8008

CrmSvcUtil.exe is a command-line code generation tool in Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online that generates early-bound .NET Framework classes that represent the entity data model entities inside Microsoft DynamicsCRM. Running the tool is the first step in using an entity data model to develop applications for Microsoft DynamicsCRM.

Important
If you have been using the CrmSvcUtil.exe tool from a pre-release (Beta) version of the 2011 SDK, you will need to delete the LiveDeviceID folder that the tool created in your system user account profile folder. The profile folder is typically located at C:\users\<username>. There are changes in the current release of the tool that are not compatible with the LiveDeviceID folder contents generated from a previous release of the tool.

The tool creates a Microsoft Visual C# or Microsoft Visual Basic .NET file that contains strongly-typed classes for the entities in your organization, including custom entities and attributes. This output file contains one class for each entity, providing early binding and IntelliSense to aid you as you write custom code. The generated classes are partial classes that can be extended with custom business logic in separate files.

The tool can also be used to generate a class derived from the OrganizationServiceContext class that acts as an entity container in the entity data model. This service context provides the facilities for tracking changes and managing identities, concurrency, and relationships. This class also exposes a SaveChanges method that writes inserts, updates, and deletes records in Microsoft DynamicsCRM. For more information about how to use the organization service context class, see Use the Organization Service Context Class.

The code generation tool takes several parameters that determine the contents of the file that is created. The parameters can be passed in from the command line when you run the tool or in a .NET-connected application configuration file. The configuration file uses the standard key/value pairs in the appSettings section. If you provide a value from the command line in addition to in the application configuration file, the value supplied on the command line is used.

If any parameters are supplied on the command line that do not match one of the expected parameters, the tool displays the usage information. Any key/value pairs found in the application configuration file that do not match any of the expected parameters are ignored as they may be used by one of the extensibility services or are required for customization.

You can find the utility in the SDK download package in the SDK\Bin folder.

The classes created by the code generation tool are designed to be built into a class library that can be referenced by projects that use Microsoft DynamicsCRM. After you have generated the classes using the tool, you should add the file that contains the classes to your Visual Studio project or solution. You must also add references to several assemblies to work with the generated classes.

The following table lists assemblies that must be referenced when you use the generated code file.

Assembly

Assembly location

Microsoft.Crm.Sdk.Proxy.dll

Microsoft.Xrm.Sdk.dll

For the on-premises or Internet-Facing Deployment (IFD) versions of Microsoft DynamicsCRM, browse to the SDK\Bin\ folder.

For Microsoft Dynamics CRM for Outlook Online, browse to the SDK\Bin\Online\ folder.

Run the Code Generation Utility

Run this utility from the SDK\Bin folder. If you run the utility from another location, the Microsoft.Xrm.Sdk.dll assembly, located in the SDK\Bin folder, must be located in the same folder as the utility program.

The following sample shows the format for running the utility from the command line for an on-premises installation of Microsoft DynamicsCRM. You supply the parameter values for your installation.

CrmSvcUtil.exe /url:http://<servername>/<organizationname>
/XRMServices/2011/Organization.svc /out:<outputfilename>.cs /username:<username> /password:<password> /domain:<domainname> /namespace:<outputnamespace> /serviceContextName:<service context name>
CrmSvcUtil.exe /?

When running the tool against Microsoft Dynamics CRM Online, you must provide additional deviceid and devicepassword parameters on the command line. You can obtain values for these parameters by first compiling and running the DeviceRegistration code sample as described below. Use your Windows Live ID for the username parameter.

Generate your individual device ID and password

  1. Open and build the DeviceRegistration project: SDK\Tools\DeviceRegistration\DeviceRegistration.csproj.

  2. Run the executable from the command line. To register your device, set the /operation parameter to Register.

    C:\deviceregistration.exe /operation:Register
  3. Copy the displayed device ID and password values and use them as the deviceid and devicepassword parameter values when running the CrmSvcUtil code generation tool.

Parameters

The following table lists the code generation utility parameters and a gives a brief description of their use.

Parameter Shortcut Description Required

deviceid

di

Device ID used when you connect to the online server for authentication.

False

devicepassword

dp

Device password that is used when you connect to the online server for authentication.

False

domain

d

The domain to authenticate against when you connect to the server.

False

url

The URL for the Organization service.

True

out

o

The file name for the generated code.

True

language

l

The language to generate the code in. This can be either 'CS' or 'VB'. Default value is 'CS'.

False

namespace

n

The namespace for the generated code. Default namespace is the global namespace.

False

username

u

The user name to use when you connect to the server for authentication.

False

password

p

The password to use when you connect to the server for authentication.

False

servicecontextname

The name of the generated organization service context class. If no value is supplied, no service context is created.

False

help

?

Show usage information.

False

nologo

Suppress the banner at runtime.

False

Examples

The following examples show how to use of the code generation utility from the command line for each deployment type. Note that user name and password are optional parameters. If your credentials for the target Microsoft DynamicsCRM server are stored in the Windows credential vault, you do not have to provide them to run the code generation tool.

Claims Authentication Active Directory

The following sample shows how to run the code generation utility using claims authentication via Active Directory. Note the use of https as this sample server is using Secure Socket Layer (SSL).

CrmSvcUtil.exe /url:https://myport:555/MyOrg/XRMServices/2011/Organization.svc /out:GeneratedCode.cs
   /username:administrator /password:password

Microsoft Dynamics CRM Online

The following sample shows how to run the code generation utility for Microsoft Dynamics CRM Online.

CrmSvcUtil.exe /url:https://myorg.crm.dynamics.com/XRMServices/2011/Organization.svc /out:GeneratedCode.cs /username:"myname@live.com" /password:"myp@ssword!" /deviceid:"9eqd9qip4meckbxhyi838gn3" /devicepassword:"543opae9itRWKO+U7fe+I3MRVANUyFFPcfDJYP5ItZo="

Claims Authentication - IFD

The following sample shows how to run the code generation utility using claims authentication.

CrmSvcUtil.exe /url:https://myorg.crm.com:555/XRMServices/2011/Organization.svc /out:GeneratedCode.cs /username:administrator /password:p@ssword! 

Sample Configuration File

If a CrmSvcUtil.exe.config configuration file is provided, it must reside in the same folder as the tools executable. The file uses the standard key/value pairs in the appSettings section. If you provide a value from the command line in addition to one in the application configuration file, the value supplied on the command line is used. Any key/value pairs found in the application configuration file that do not match any of the expected parameters are ignored as they may be used by one of the extensibility services or are required for customization.

The url and namespace required parameters should not be supplied in the configuration file. This requires anyone using the utility to provide these required values for the parameters on the command line when executing the tool.

The following sample shows how to configure the output file and the domain name parameters in the application configuration file using shortcut keys.

Xml
<appSettings>
    <add key="o" value="CrmProxy.cs"/>
    <add key="d" value="mydomain"/>
</appSettings>

To enable tracing when the tool is run, add the following code lines to the configuration file.

<system.diagnostics> 
   <trace autoflush="false" indentsize="4"> 
      <listeners> 
         <add name="configConsoleListener" type="System.Diagnostics.ConsoleTraceListener"> 
            <filter type="System.Diagnostics.EventTypeFilter" initializeData="Error" /> 
         </add> 
      </listeners> 
   </trace> 
</system.diagnostics>

Create Extensions for the Code Generation Tool

You can extend the functionality of the code generation tool by specifying additional command line parameters and parameter values. To specify a parameter, add the following to the command line: /<parametername>:<class name>,<assembly name>. Note that assembly name does not include the .dll extension. As an alternative, you can add the equivalent value to the config file in the format<add key=<parametername> value=<class name>,<assembly name> />.

There is a parameter for each extension. The following table lists each of the possible extensions.

Parameter Name Interface Name Description

/codecustomization

ICodeCustomizationService

Called after the CodeDOM generation has been completed (assuming the default instance of ICodeGenerationService). It is useful for generating additional classes, such as the constants in Picklists, etc.

/codewriterfilter

ICodeWriterFilterService

Called during the process of CodeDOM generation (assuming the default instance of ICodeGenerationService) to determine whether a specific object/property should be generated.

/codewritermessagefilter

ICodeWriterMessageFilterService

Called during the process of CodeDOM generation (assuming the default instance of ICodeGenerationService) to determine whether a specific message should be generated. This should not be used as requests/responses as these are already generated in Microsoft.Crm.Sdk.Proxy.dll and Microsoft.Xrm.Sdk.dll

/metadataproviderservice

IMetadataProviderService

Called to retrieve the metadata from the server. This may be called multiple times during the generation process, so the data should be cached.

/codegenerationservice

ICodeGenerationService

Core implementation of the CodeDOM generation. If this is changed, the other extensions may not behave in the manner described.

/namingservice

INamingService

Called during the CodeDOM generation to determine the name for objects (assuming the default implementation).

The implementation of the above interfaces must have one of the following constructors:MyNamingService()MyNamingService(INamingService defaultService)MyNamingService(IDictionary<string, string> parameters)MyNamingService(INamingService defaultService, IDictionary<string, string> parameters)

If the implementation has one of these constructors, it is constructed with the appropriate values. Once it has been instantiated, the interface is used according to the above definitions.

See Also


© Resultondemand.nl   Hosting -  Performance -  Upgrade -  Nieuw -  Over ons -  Contact -  CRM 2011 proberen

2AT - Netricity - CRM boeken

Microsoft Partner? Bekijk hier ons partner aanbod