Reputation: 4432
I have setup a test Dynamics CRM 2011 server.
I've used the SDK's CrmSvcUtil utility to generate the early bound entity classes (e.g. mycrm.cs).
I've created a new project in Visual Studio and added references to Microsoft.CRM.SDK.Proxy, Microsoft.Xrm.Sdk, and System.Runtime.Serialization.
I've also added the mycrm.cs file to my project as an existing file.
Now what?
I know, I know...read the SDK. I've tried:
Using the Early Bound Entity Classes in Code
Using the Early Bound Entity Classes for Create, Update, Delete
Create Early Bound Entity Classes with the Code Generation Tool (CrmSvcUtil.exe)
Call me an idiot if you must - I'm sure these articles probably include the info. I need, but I'm not seeing it. Help!
Upvotes: 3
Views: 6285
Reputation: 2017
First, you need to connect to CRM web service:
OrganizationServiceProxy orgserv;
ClientCredentials clientCreds = new ClientCredentials();
ClientCredentials devCreds = new ClientCredentials();
clientCreds.Windows.ClientCredential.UserName = "user";
clientCreds.Windows.ClientCredential.Password = "P@$$w0rd";
clientCreds.Windows.ClientCredential.Domain = "myDomain";
IServiceConfiguration<IOrganizationService> orgConfigInfo =
ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(new Uri("https://myCRMServer/myOrg/XRMServices/2011/Organization.svc"));
orgserv = new OrganizationServiceProxy(orgConfigInfo, clientCreds);
orgserv.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
After that, you are going to use your XrmServiceContext, or how you name it here:
CrmSvcUtil.exe /url:http://servername/organizationname/XRMServices/2011/Organization.svc /out:.cs /username: /password: /domain: /namespace: /serviceContextName:XrmServiceContext
Then you can start with CRUD examples from link you posted :)
Example for updating contact:
using(var context = new XrmServiceContext(orgserv))
{
Contact con = context.contactSet.FirstOrDefault(c => c.Name == "Test Contact");
if(con != null)
{
con.City = "NY";
context.UpdateObject(con);
context.SaveChanges();
}
}
Hope it helps :)
Upvotes: 7