Question

In CRM 4, I used to add web reference in my visual studio project of the CRMService.asmx and it would bring me all the entities (including custom entities) and all the services.

Now I've moved to CRM 2011 and I dont really understand complitely how it works over here..when I add the web reference of organization.svc it won't add my custom entities, when I use the crmSvcUtil.exe then it generates classes for all the entities (including the custom entities) but no services..So how do I work with organization.svc in CRM 2011? Do I just need to use crmSvcUtil or combine it with the web reference of organization.svc?

Was it helpful?

Solution

In CRM 2011 you dont add a reference to the webservice as you did in CRM 4. If you want early bound entity classes then you will have to generate this with the crmsvcutil.exe. If you are going to use LINQ to query your CRM data then add the /serviceContextName:contextname and a OrganizationServiceContext will be generated in the code file.

If you dont care about early bound entity classes then you can use the entity class. In 2011 you use the entity class insted of what was called DynamicEntity in CRM 4.

In order to do anything with CRM 2011 you will have to add some references to your project, you will find them in the bin folder where you have the sdk.

You will always add a reference to Microsoft.Xrm.Sdk. If you will use early bound you will also need a reference to Microsoft.Crm.Sdk.Proxy. And from the standard .Net libraries you will have to add references to System.ServiceModel and System.Runtime.Serialization

To connect to CRM 2011 you will use the OrganizationServiceProxy.

var organizationUri = new Uri("http://<servername>/<organizationname>/XRMServices/2011/Organization.svc");
var credentials = new ClientCredentials();

var serviceProxy = new OrganizationServiceProxy(organizationUri, null, credentials, null);
// If you use early bound entity classes, you have to include the line below. Not needed on late bound
serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

Then by using the serviceproxy already created I can start working with the CRM data. For creating an account:

var account = new Account();
account.Name = "Testing";
serviceProxy.Create(account);

Some link for futher reading:

DiscoveryService

Using the IOrganizationService

Using Organization Service Context

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top