CRM 2011 : all operations with pure OrganizationServiceClient call

After working with CRM 2011 for all kinds of crude operations(create, update, delete, share, unshare, activate, inactivate, owner assignment, retrieve) without using any external dll or class files(XRM.dll or early bound class generated by utiltool from sdk), it is quite visible to me that actually all the operations can be done using pure WCF call with the method “OrganizationRequest”. Also, to achieve this, we need to modify a few class definations in the Reference.cs class file auto generated by the WCF(.svc) call. I will summarize some earier ways to achieve this without making changes in Reference.cs file or any other external modifications:

1. Add CRM 2011 WCF Service Reference(.svc) to your ASP.NET project.

2. Add an external class file with the exact namespace of the Reference.cs file(this namespace consists of the namespace of the ASP.NET project with namespace of the Service Reference that you have added to above).

3. Add these below 3 partial classes without any definations to get rid of all unnecessary serialization errors with pure WCF calls to CRM 2011:

[System.Runtime.Serialization.KnownTypeAttribute(typeof(OptionSetValue))] // for AllColumns in Retrieve() / ColumnSet

 [System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityReference))] // for AllColumns in Retrieve() / ColumnSet

 public partial class Entity{ }

 

[System.Runtime.Serialization.KnownTypeAttribute(typeof(OptionSetValue))]// for AllColumns in RetrieveMultiple() / ColumnSet

 [System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityReference))] // for AllColumns in RetrieveMultiple() / ColumnSet

 public partial class EntityCollection{ }

 

[System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityReference))] // for update owner, Share, Unshare

[System.Runtime.Serialization.KnownTypeAttribute(typeof(PrincipalAccess))] // update owner, Share, Unshare

[System.Runtime.Serialization.KnownTypeAttribute(typeof(OptionSetValue))] // inactivate, activate

 public partial class OrganizationRequest{ }

 

4. Below are the details for each type of crude operation to CRM(for details, please check the other blogs present in this site):

 CREATE/ UDATE/ DELETE: with pure  OrganizationServiceClient object 

(OrganizationServiceClient object).Create(Entity)/Update(Entity)/Delete(Entity, Entity id);

ACTIVATE/INACTIVATE : with the help of “OrganizationRequest” object.

OrganizationRequest _objInactivate = new OrganizationRequest() { Parameters = new ParameterCollection(), RequestName = “SetState” };

 SHARE/ UNSHARE: with the help of “OrganizationRequest” object.

OrganizationRequest _objShare = new OrganizationRequest() { Parameters = new ParameterCollection(), RequestName = “GrantAccess”/”RevokeAccess”};

 OWNER UPDATE(ASSIGNMENT) : with the help of “OrganizationRequest” object-

OrganizationRequest _objUpdateOwner = new OrganizationRequest(){ RequestName = “Assign”, Parameters = new ParameterCollection() };

 RETRIEVE/ RETRIEVEMULTPLE: with the help of “OrganizationRequest” object.

(OrganizationRequest object).RetrieveMultiple(Query object) / Retrieve(“entity”,”entity id”,”columnset”);

 

note: details of each operation type can be found on other blogs in this same site under my user id.

 

regards

joon

Advertisements

About Joon
quite ordinary man

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: