Using Organization.svc in Silverlight for CRM 2011 Online/OnPremise


  • Create a new Silverlight 4 Application named CRM2011OnlineSilverlightApp.
  • Add Service Reference to the Organization.Svc (https://orgname.crm4.dynamics.com/XrmServices/2011/Organization.svc).
  • crm for North America
  • crm4 for Europe
  • crm5 for Asia
    • Give the namespace as OrgServiceReference
  • Open the reference.cs and replace System.Collections.Generic.KeyValuePair with KeyValuePair
  • Add the following helper files from the SDK (..\sdk\samplecode\cs\silverlight\soapforsilverlight\soapforsilverlightsample)
  • silverlightextensionmethods.cs
  • silverlightutility.cs
  • Rename namespace SoapForSilverlightSample.CrmSdk to CRM2011OnlineSilverlightApp.OrgServiceReference in silverlightextensionmethods.cs file.
  • Add a Button and a TextBlock to our Silverlight application.
  • Add the following code.
 private void btnCreateContact_Click(object sender, RoutedEventArgs e)
 {
 // Get IOrganizationService instance
 IOrganizationService myOrgService = SilverlightUtility.GetSoapService();

Entity myContact = new Entity();
 myContact.LogicalName = "contact";

// Create the AttributeCollection
 myContact.Attributes = new AttributeCollection();

// Specify Last Name and First Name for the contact to be created
 KeyValuePair<string, object> myKVPLastName = new KeyValuePair<string, object>();
 myKVPLastName.Key = "lastname";
 myKVPLastName.Value = "Twain";

 KeyValuePair<string, object> myKVPFirstName = new KeyValuePair<string, object>();
 myKVPFirstName.Key = "firstname";
 myKVPFirstName.Value = "Shania";

myContact.Attributes.Add(myKVPLastName);
 myContact.Attributes.Add(myKVPFirstName);

 OrganizationRequest myOrgRequest = new OrganizationRequest();
 myOrgRequest.RequestName = "Create";

// call the Create method
 myOrgService.BeginCreate(myContact, myCreateHandler, myOrgService);
 }

private void myCreateHandler(IAsyncResult ar)
 {
 IOrganizationService orgService = ar.AsyncState as IOrganizationService;

Dispatcher.BeginInvoke(() =>
 {
 txtStatus.Text = "Contact Guid - " + orgService.EndCreate(ar);
 });
 }
  • Create a web resource in CRM and upload the XAP, and to test it add it to any form inside CRM.
  • Click on create to create the contact record.
  • Download the project.  (change the extension to zip from docx)
Hope it helps.

https://nishantrana.me/wp-content/uploads/2011/11/crm2011onlinesilverlightapp.docx


Discover more from Nishant Rana's Weblog

Subscribe to get the latest posts sent to your email.

Unknown's avatar

Author: Nishant Rana

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

9 thoughts on “Using Organization.svc in Silverlight for CRM 2011 Online/OnPremise”

  1. I tried a fetchxml for getting some records under the same above framework. BUt , it does not show me anything .. not even error on page. Could you please tell me where i am going wrong ?

    public void getDiagnosesFromCRM(string strLeadId)
    {
    string fetchDiagnose = “” +
    “” +
    “” +
    “” +
    “” +
    “” +
    “” +
    “” +
    “” +
    “” +
    “” +
    “” +
    “”;
    FetchExpression fetchQuery = new FetchExpression()
    {
    Query = fetchDiagnose
    };

    OrganizationRequest request = new OrganizationRequest() { RequestName = “RetrieveMultiple” };
    request[“Query”] = fetchQuery;

    IOrganizationService service = SilverlightUtility.GetSoapService();

    service.BeginExecute(request, new AsyncCallback(getDiagnosesFromCRM_Handler), service);
    }

    public void getDiagnosesFromCRM_Handler(IAsyncResult result)
    {
    try
    {
    OrganizationResponse response = ((IOrganizationService)result.AsyncState).EndExecute(result);
    EntityCollection results = (EntityCollection)response[“EntityCollection”];

    if (results.Entities.Count == 0)
    {
    //sb.AppendLine(“There are no Account records in the system.”);
    }
    else
    {
    List collDiagnoses = new List { };
    foreach (c4h_sl_leadDiagnoses.OrgServiceReference.Entity entity in results.Entities)
    {
    Diagnose objDiagnose = new Diagnose();
    objDiagnose.Name = entity.GetAttributeValue(“new_name”);
    collDiagnoses.Add(objDiagnose);
    }
    dgDiagnoses.ItemsSource = collDiagnoses;
    }
    }
    catch (Exception ex)
    {
    ;
    }
    }

    // A local class
    public class Diagnose
    {
    public string Name { get; set; }
    }
    ==============
    dgDiagnoses is a datagrid , which otherwise with hardcoded values, shows properly.

    The fetch xml when tested on a normal sdk framework application gave ne proper list of results!
    But in this BeginExecute and EndExecute … it does not !

    Like

  2. Hi,

    Thank you ! Just like as in the post, i am create a Task instead of contact.

    How do i ::

    1) Assign the task to a particular user. Ie, Set the OwnerId. “assignrequest’ equivalent in SOAP Endpoint.

    2. The regarding object Id was set. How do we specify the the type of the regardingobjectid?

    If you could help me with these two show stoppers of mine at the moment, it would be great !!! 🙂

    Thanks in Advance ….

    Like

  3. Hi Nishant,

    I am bit stuck with updating the reference.cs file, the image you provided allows to browse through, but in my application it does not gives that option. Any idea how to go about it. I can open the file from the folder.but when I update I get some more errors…Any suggestions are welcomed.

    Thanks

    Like

Leave a reply to Nisha Cancel reply

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

Discover more from Nishant Rana's Weblog

Subscribe now to keep reading and get access to the full archive.

Continue reading

Power Platform Puzzles

D365 CRM, Power Platform Tips &Tricks

Power Spark

Power Spark By Shrangarika

Van Carl Nguyen

Exploration of Power Platform

My Trial

It is my experience timeline.

Power⚡Thomas

Sharing my knowledge and experience about the Microsoft Power Platform.

Arpit Power Guide

a guide to powering up community

Welcome to the Blog of Paul Andrew

Sponsored by Cloud Formations Ltd

Deriving Dynamics 365

Deriving Solutions and features on Power Platform/Dynamics 365

The CRM Ninja

Thoughts & musings from a Microsoft Business Applications Ninja!

D CRM Explorer

Learn about Microsoft Dynamics CRM Power Platform customization and implementation and other cool stuffs

Stroke // Jonas Rapp

I know pre-stroke. I will improve who I was.

Power Melange

Power Melange By Shalinee

Clavin's Blog - PPUG.ORG

AI - Power Automate - Power Apps - SharePoint Online - Azure - Nintex - K2 - Artificial Intelligence

Sat Sangha Salon

An Inquiry in Being

The Indoencers

The Influencers & Influences of Indian Music

Monika Halan's blog

Hand's-free money management

D365 Demystified

A closer look at Microsoft Dynamics 365.

Microsoft Mate (msftmate) - Andrew Rogers

Experienced consultant primarily focused on Microsoft Dynamics 365 and the Power Platform

Manmit Rahevar's Blog

One Stop Destination for Microsoft Technology Solutions

MG

Naturally Curious

Brian Illand

Power Platform and Dynamics 365

Steve Mordue

The Professional Paraphraser

Subwoofer 101

Bass defines your home theater

SQLTwins by Nakul Vachhrajani

SQL Server tips and experiences dedicated to my twin daughters.

Everything D365

Discovering Azure DevOps and D365 Business Applications

Tech Wizard

Lets do IT Spells

XRM Tricks (Power Platform & Dynamics CRM )

Power Platform & Dynamics CRM

CRM TIPS BY PRM

Mail to crmtipsbyprm@gmail.com for queries and suggestions

nijos.dev

Giving back to the community what I have learned

Power Platform Learning

Your Go-To Resource for Power Apps, Power Automate & More

xrm CRM Dynamics

Dynamics CRM Technical & Functional Info

Dynamics 365 Blogs - Explained in unique way

Sometimes you need to look at things from different perspective.