CRM 2011, C#: OrganizationRequest and OrganizationResponse with .Net version 3.5

We already discussed how a CRM 2011 web service can help us create object of OrganizationServiceProxy or Instance of IOrganizationService in my previous posts. This is the case when we’re not using assemblies from SDK and thus several SDK request and response messages will not be available to you like RetrieveAttributeRequest/Response etc.

All we have is OrganizationRequest and OrganizationResponse and in this case you will have to use OrganizationRequest and OrganizationResponse to request data from CRM 2011. See below example which uses similar example for RetrieveAttributeRequest.

OrganizationRequest request = new OrganizationRequest();
request.RequestName = "RetrieveAttribute";
request.Parameters = new ParameterCollection();
request.Parameters.Add(new KeyValuePair<string, object>("EntityLogicalName", "salesorder"));
request.Parameters.Add(new KeyValuePair<string, object>("RetrieveAsIfPublished", true));
request.Parameters.Add(new KeyValuePair<string, object>("LogicalName", "new_cardtype"));

    OrganizationResponse response = (OrganizationResponse)CrmHelper.OrgService.Execute(request);
    PicklistAttributeMetadata picklist = (PicklistAttributeMetadata)response.Results[0].Value;
catch (FaultException<OrganizationServiceFault> ex)
    throw new Exception("Error details: " + ex.Message);

Happy Programming!


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s