1. Create a console application in VS.
2. Download CRM SDK from http://xrm.tools/SDK
3. Inside the Project Reference folder Add these reference from Downloaded SDK's reference folder also you have other references in your local system you can add it by right clicking the reference folder selecting add reference
4. Code is below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Sdk.Query;
namespace ConsoleConnectToCRMUsingWebApi
{
class Program
{
static void Main(string[] args)
{
#region credentials
string SoapOrgServiceUri = "https://Orgname.api.crm.dynamics.com/XRMServices/2011/Organization.svc";
ClientCredentials credentials = new ClientCredentials();
credentials.UserName.UserName = "UserName";
credentials.UserName.Password = "Password";
#endregion
Uri serviceUri = new Uri(SoapOrgServiceUri);
OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, credentials, null);
proxy.EnableProxyTypes();
IOrganizationService orgService = (IOrganizationService)proxy;
Guid accountId = new Guid("475b158c-541c-e511-80d3-3863bb347ba8");
Entity entity = orgService.Retrieve("account", accountId, new ColumnSet("name"));
Console.WriteLine("account name: {0}", entity["name"]);
Console.ReadLine();
}
}
}
5. Output will be look like
Thank you!

No comments:
Post a Comment