Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Using the Generated Classes in Your Project

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

The classes that are output by the CrmSvcUtil code generation tool are designed to be built into a class library that can be referenced by your projects that use Microsoft Dynamics CRM. This is the recommended approach. After you have generated classes for your organization using CrmSvcUtil, you should move the files to the folder for your Visual Studio project and then add them to the solution.

In order to work with the classes you also need to add references to the following Microsoft Dynamics CRM and .NET assemblies:

Add references to these assembliesAssembly location
Microsoft.Crm.Sdk.dll

Microsoft.Crm.SdkTypeProxy.dll

For on-premises or IFD, browse to the SDK\Bin (32-bit) or SDK\Bin\64-bit folder.

For online, browse to the SDK\Bin\Online\64-bit folder. These assemblies work in both 32-bit and 64-bit environments.

Microsoft.Xrm.Client

Microsoft.Xrm.Portal

Microsoft.Xrm.Portal.Files

From the SDK\Microsoft.Xrm\Bin folder.
System.Data.Services

System.Data.Services.Client

From the .NET tab.

For all examples in this document, the XrmDataContext has been generated by CrmSvcUtil without using the /useDisplayNames switch. This means that the objects and properties will all be based on the logical names of the entities rather than the metadata labels. For example, the class will be called "account" rather than the display name "Account"; the contact First Name attribute will be called "firstname" rather than the display name "FirstName".

All of the code samples in this document were generated using the following connection string:

crmsvcutil /connectionString:"Authentication Type=Passport; Server=https://crm-org-name.crm.dynamics.com/org-id; User ID=user-wlid-email; Password=user-wlid-pwd; Device ID=user-defined-deviceid; Device Password=user-defined-devicepwd" /out:"Xrm.cs" /namespace:Xrm /dataContextPrefix:Xrm

Accessing the CrmService from a Plug-in

The following sample code shows how to get the Web service and generated classes from a plug-in.

/*Define the connection with the impersonated user*/
CrmConnection crmc = CrmConnection.Parse("Authentication Type=Passport; Server=https://" + org + ".crm.dynamics.com/" + org + "; User ID=myuser; Password=mypassword; Device ID=mydeviceid; Device Password=mydevicepassword");
crmc.ImpersonatedUser = new Guid(userid);
var crmOnline = new DataContext(crmc);

List<opportunity> uplist = new List<opportunity>();

crmOnline.UsingService(service =>
{
  var query = from o in crmOnline.opportunityopportunities
  select o;

  foreach (opportunity thisopp in query)
  {
    uplist.Add(thisopp);
  }
});

See Also

Concepts


© 2010 Microsoft Corporation. All rights reserved.


Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.