3
votes

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!

1
What is the problem? What you wanna do? All communication with Dynamics based on its services, all you could do is to call it methods from solution. Another way to extend CRM is to create packages from UI with custom entities or groups or whatever.user854301
I want to perform CRUD operations on my CRM. I have an independent internet facing application and I want to sync info. from this app. into Dynamics CRM.Dave Mackey
Have you connected to OrganizationService? Can you obtain from this services any thing?user854301
No, but I haven't been able to find code for this, only for OrganizationServiceProxy.Dave Mackey

1 Answers

7
votes

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 :)