Using OrganizationServiceClient in CRM 2011

 Add Service Reference to the Organization WCF service in the application.

URL àhttp://servername:port/OrganizationName/xrmServices/2011/organization.svc 

Use the following code to perform various functions using OrganizationServiceClient 

Entity myContact = new Entity();

myContact.LogicalName = “contact”; 

AttributeCollection myAttColl = new AttributeCollection();

myAttColl.Add(new KeyValuePair<string, object>(“lastname”, “Rana”));

myContact.Attributes = myAttColl;
ClientCredentials credentials = new ClientCredentials();

Uri organizationUri = new Uri(http://servername:port/organizationname/xrmServices/2011/organization.svc&#8221;);

OrganizationServiceClient orgClient = new OrganizationServiceClient();

orgClient.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(“username”, “password”, “domain”); 


catch (Exception ex)

throw ex;


Hope it helps.


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

12 thoughts on “Using OrganizationServiceClient in CRM 2011”

  1. Everywhere, of course, with the exception of the
    Hellenestic Greek States. This will probably come naturally, especially if you dominate the Ultralisk instead of letting it rampage on its own, since it gets
    a rack of kills on its destruction run. With the amount of possibilities the demo
    suggests, it would seem this is THE game to keep your peepers open for.


  2. I found this will Close Incidents, However I still can not programatically close the associated activities.

    Entity caseResolution = new Entity(“incidentresolution”);
    caseResolution.Attributes.Add(“incidentid”, new EntityReference(“incident”, new Guid(“MYGUIDHERE”)));
    caseResolution.Attributes.Add(“subject”, “testing programatic closing.”);


    Microsoft.Crm.Sdk.Messages.CloseIncidentRequest req = new Microsoft.Crm.Sdk.Messages.CloseIncidentRequest();
    req.IncidentResolution = caseResolution;
    req.RequestName = “CloseIncident”;
    OptionSetValue o = new OptionSetValue();
    o.Value = 5;
    req.Status = o;

    Microsoft.Crm.Sdk.Messages.CloseIncidentResponse resp = (Microsoft.Crm.Sdk.Messages.CloseIncidentResponse)service.Execute(req);


  3. This code connects to CRM But I dont know how to close the incidents after Could someone help me?
    string crmServerUrl = “http://myserver/mygroup/”;
    string connectionStringIntegrated = string.Format(“Url={0};”, crmServerUrl);
    string connectionString = connectionStringIntegrated;

    var connection = CrmConnection.Parse(connectionString);

    using (var service = new OrganizationService(connection))

    using (var crm = new CrmOrganizationServiceContext(service))
    //Resolve Incidents and Cancel Incidents in here by passing in the incidentID



  4. Hi, nice article.
    However, when we try to add an address to an account, that we made up your way, it tells us we need to specify the ‘parentid’. We’ve done this, but then it throws an exception that the parentid cannot be NULL. Whilst debugging it doesn’t show that its null.

    Can you help us out?



  5. Hi Nishant,

    Hope you are doing well.
    I am trying to retrieve data from “CRM 2011” using “Organization” webservice.
    Whenever I am trying to connect this webservice it gives “Server not found error Error”.

    So my question is whether “CRM 2011” supported by “Windows Phone 7” or not?

    Please help 😦


Please share your thoughts

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.