Translate

Friday, 9 December 2016

Generate Organization service using Microsoft.Xrm.Client dll

How to generate organization service using Microsoft.Xrm.Client dll ?

Hello CRM Developers,
          This is my new post to generate organization service in CRM 2013,2015 and 2016. Simplest method to generate organization service, for this only two line of C# code will be required.

For generation organization service below assemblies are required.
  1. Microsoft.Xrm.Sdk.dll
  2. Microsoft.Xrm.Client.dll
  3. System.configuration
And below name spaces will be required
  1. using Microsoft.Xrm.Client;
  2. using Microsoft.Xrm.Client.Services;
  3. using Microsoft.Xrm.Sdk;
  4. using Microsoft.Xrm.Sdk.Client;
  5. using Microsoft.Xrm.Sdk.Query;

 Add below code in .cs file and App config file respectively. 

//.CS File Code

public IOrganizationService getOrganizationService(string key)
{
    CrmConnection con = new CrmConnection("CRMOnline");
    IOrganizationService service = new OrganizationService(con);
    OrganizationServiceContext Context = new OrganizationServiceContext(service);
    return service;
}

//App config file code

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version = "v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <connectionStrings>   
    <add name = "CRMOnline" connectionString="Url=https://Your Organization URL/XRMServices/2011/Organization.svc; Username=xyz; Password=xyzpassword;"/>
  </connectionStrings>

</configuration>
 

Enjoy the great technology Dynamics CRM. Good luck.....!!!!! 
Please feel free to put comments for your queries.Thanks.
Post a Comment