locked
Custom Entity Retrieval RRS feed

  • Question

  • Hi all,


    I was wondering if there was any way to retrieve a strongly typed custom class in .net code.
    I know it's possible with built in entities like account.
    If not then how do you access and cast all the different field types.

    Here's what i am currently using but it seems a bit sloppy and i'm unsure on how to cleanly get all the values

     

    var query = new QueryExpression();
        query.EntityName = "new_entity";
    
        ColumnSet columns = new ColumnSet();
        columns.Attributes.Add("new_name");
        columns.Attributes.Add("ownerid"); //owner
        columns.Attributes.Add("new_field1"); // lookup
        columns.Attributes.Add("new_field2");
        columns.Attributes.Add("new_field3"); // date
        columns.Attributes.Add("new_field4"); // lookup
        columns.Attributes.Add("new_field5"); // int
        //...
    
        query.ColumnSet = columns;
    
    
    
        var crmService = CrmServiceUtility.GetCrmService("http://mywebsite", "site");
    
        RetrieveMultipleRequest request = new RetrieveMultipleRequest();
        request.Query = query;
        request.ReturnDynamicEntities = true;
    
        RetrieveMultipleResponse response = (RetrieveMultipleResponse)crmService.Execute(request);
    
        foreach (BusinessEntity be in response.BusinessEntityCollection.BusinessEntities)
        {
          DynamicEntity de = (DynamicEntity)be;
          foreach (Property prop in de.Properties)
          {
            // Don't really know how to do this part cleanly
          }
        }

     

    Thanks in advance

    Wednesday, June 16, 2010 5:33 PM

Answers

  • Wednesday, June 16, 2010 5:59 PM
    Moderator
  • Hi

    if you SDK webservices to get CRM data then you need to download the WSDL file from the CRM server...and update the referance in your C# project as follows...

    Download WSDL files

     1. Log on to CRM - > Settings -> Customization - > Download Web Service Description Files
     2. This will display two options crmservice.asmx and metadataservice.asmx.
     3. Click on metadataservice.asmx first and it will open up in new window as XML...in this new window click on File --> Save as and save it to particular location as <<name>>.XML
     4. follow similair step for crmservice.asmx

    Add this as Web Referance in your visual studio project .. as follows 

     1. Click on Add Web Referance 
     2. Put the file path in the URL (C:\web services referance\MetadataService.xml) and then put the web referance name and click ok.

    Updating would be just to right click on web service and select update web Referance..

    once this is doen it will work fine...

     

    Wednesday, June 16, 2010 8:52 PM

All replies