web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Problem Retrieving Records using CRM SOAP service

(0) ShareShare
ReportReport
Posted on by 630

Hi,

I'm trying to consume a CRM Organization SOAP service form a C# console application, but whenever I call the following code I get an exception regarding destabilization.

Here is my code:

string strURI = @"serveraddress/.../Organization.svc";
CRMService.OrganizationServiceClient orgProxy = new OrganizationServiceClient();

orgProxy.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("username", "password", "domain");

System.ServiceModel.EndpointAddress myEndpointAdd = new System.ServiceModel.EndpointAddress(new Uri(strURI), System.ServiceModel.EndpointIdentity.CreateDnsIdentity(""));
ColumnSet columns=new ColumnSet();
columns.Columns=new string[]{"name","parentaccountid"};
orgProxy.Endpoint.Address = myEndpointAdd;
var test = orgProxy.Retrieve("account", new Guid("25691CAF-DEDF-E511-80C2-005056895026"), columns);

 Exception:

An unhandled exception of type 'System.ServiceModel.Dispatcher.NetDispatcherFaultException' occurred in mscorlib.dll

Additional information: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter schemas.microsoft.com/.../Services:RetrieveResult. The InnerException message was 'Error in line 1 position 783. Element 'schemas.datacontract.org/.../System.Collections.Generic:value' contains data from a type that maps to the name 'schemas.microsoft.com/.../Contracts:EntityReference'. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver if you are using DataContractSerializer or add the type corresponding to 'EntityReference' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to the serializer.'. Please see InnerException for more details.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    nghieppham Profile Picture
    4,755 on at

    Hi Osama.

    You should chekc the ID that you passed "25691CAF-DEDF-E511-80C2-005056895026", it must be tolower.

    Regards,

  • Suggested answer
    Community Member Profile Picture
    on at

    Please try this

    using Microsoft.Xrm.Client;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Query;
    using System;
    using System.Text;

           IOrganizationService organizationService = null;

           Uri uri = new Uri("URI");

           string connectionString = string.Format(@"Url={0}; Username={1}; Password={2};",

                                                   uri,

                                                   "UserName",

                                                   "Password");

           CrmConnection connection = CrmConnection.Parse(connectionString);

           organizationService = new Microsoft.Xrm.Client.Services.OrganizationService(connection);

           ColumnSet columns = new ColumnSet("name", "parentaccountid");

           Entity retrievedEntity = organizationService.Retrieve("account", new Guid("25691CAF-DEDF-E511-80C2-005056895026"), columns);

  • Verified answer
    Ozarour Profile Picture
    630 on at

    This is true if I want to use SDK to connect to CRM, but in my case I want to connect using  CRM Organization SOAP web service.

    However, the solution is to add the following line in the service reference file

    [System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityReference))]

    above the AttributeCollection class.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans