Yacov
Yacov

Reputation: 1070

How to retrive records from OData service of crm 2011 IFD

I have the fallowing code.

var ctx = new XrmContext(new Uri(serviceUrl));
ctx.Credentials = new NetworkCredential("username", "password", "domain");
ctx.AccountSet.First();

Silverlight version is (In fiddler we have here the same result)

var ctx = new AdzzContext(new Uri(serviceUri));

ctx.HttpStack = System.Data.Services.Client.HttpStack.ClientHttp;
ctx.UseDefaultCredentials = false;
ctx.Credentials = new NetworkCredential("username", "password", "admin");

var query = ctx.AccountSet;

var async = new DataServiceCollection<Account>();
async.LoadCompleted += async_LoadCompleted;
async.LoadAsync(query);

What give me the falling error.

The response payload is a not a valid response payload. Please make sure that the top level element is a valid Atom element or belongs to 'http://schemas.microsoft.com/ado/2007/08/dataservices' namespace.

When I look at fiddler I see a redirect to the adfs server Redirect

I saw this link, but it is for CRM 4, And in the context of the OData I can't put a token.

My target is so,

To make a Silverlight library for business logic (BL) purpose - So I can debug it easily in my computer - and it will run perfectly in the CRM environment,

How can I do it?

Upvotes: 0

Views: 1369

Answers (1)

Guido Preite
Guido Preite

Reputation: 15128

you need to generate the early bound classes (using crmsvcutil.exe) and specify the ServiceContextName parameter.

Assuming your context is XrmContext, you need to instantiate in this way:

var context = new XrmContext(service);

where service is the IOrganizationService web service.

You don't need to specify the credentials because the connection credentials are handled when you instantiate the OrganizationServiceProxy

Sample code: http://nishantrana.wordpress.com/2010/11/03/sample-code-for-using-iorganizationservice-in-crm-2011/

Upvotes: 1

Related Questions