Answered by:
Custom Entity Retrieval

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
-
- Marked as answer by DavidJennawayMVP, Moderator Monday, July 26, 2010 9:13 AM
Wednesday, June 16, 2010 5:59 PMModerator -
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...
- Marked as answer by DavidJennawayMVP, Moderator Monday, July 26, 2010 9:13 AM
Wednesday, June 16, 2010 8:52 PM
All replies
-
Wednesday, June 16, 2010 5:48 PMModerator
-
Also I will suggest you to look for latest SDK
http://blogs.msdn.com/b/crm/archive/2010/05/07/new-crm-sdk-new-developer-experience.aspx
http://msdn.microsoft.com/en-us/library/ff681561.aspx
Mahain- Proposed as answer by HIMBAPModerator Wednesday, June 16, 2010 5:58 PM
Wednesday, June 16, 2010 5:58 PMModerator -
- Marked as answer by DavidJennawayMVP, Moderator Monday, July 26, 2010 9:13 AM
Wednesday, June 16, 2010 5:59 PMModerator -
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...
- Marked as answer by DavidJennawayMVP, Moderator Monday, July 26, 2010 9:13 AM
Wednesday, June 16, 2010 8:52 PM