locked
Unable to cosnume CRM online using WCF Data service 5.6 RRS feed

  • Question

  • Hi,

    I'm facing an issue while pulling the data from CRM online.

    I'm using WCF Data Services 5.6.0 RTM Tools Installer .

    Here below are my code snippets. I have modified and followed the approach mentioned in the blog here.

    Once after begin Execute is called, and call back function is invoked, Im receving the following error

    In OnContanctExecutionCompleteMethod, got this error at line

    IEnumerable<new_ustest> response = query.EndExecute(result);

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

    try
    {
    tataconContext Ctx = new tataconContext(new Uri("https://XXX.crm.dynamics.com/XRMServices/2011/OrganizationData.svc/"));
    
    Ctx.SendingRequest2 += Ctx_SendingRequest2;
    var query = from contact in Ctx.new_ustestSet select contact;
    //var query = from c in Ctx.ContactSet    
    FedId.Instance.SecurityToken.SessionCookieHeader;
    //var container= new OdataReference
    ((DataServiceQuery<new_ustest>)query).BeginExecute(onContanctExecuteComplete, query);
    TxtResults.Text = string.Empty;
    }
    catch (Exception ex)
    {
     TxtResults.Text = ex.Message;
    }
    private void onContanctExecuteComplete(IAsyncResult result)
            {
    
                try
                {
    
                    var query = result.AsyncState as DataServiceQuery<new_ustest>;
                    IEnumerable<new_ustest> response = query.EndExecute(result);
    
    
                    foreach (new_ustest c in response)
                    {
                        TxtResults.Text += c.new_US_Name;
                    }
                }
                catch (Exception ex)
                {
                    TxtResults.Text = ex.Message;
                }
    
    
    
            }
    
            void Ctx_SendingRequest2(object sender, SendingRequest2EventArgs e)
            {
    
                e.RequestMessage.SetHeader(HttpRequestHeader.Cookie.ToString(), FedId.Instance.SecurityToken.SessionCookieHeader);
                e.RequestMessage.SetHeader("ContentType", "application/json;odata=verbose;charset=utf-8");
    
                // throw new NotImplementedException();
            }
    Could some one let me know where Am I going wrong


    Thanks & Regards Tejaswi Chandrapatla

    Tuesday, October 28, 2014 2:51 PM

All replies

  • Hi,

    I'm facing an issue while pulling the data from CRM online.

    I'm using WCF Data Services 5.6.0 RTM Tools Installer .

    Here below are my code snippets. I have modified and followed the approach mentioned in the blog here.

    Once after begin Execute is called, and call back function is invoked, Im receving the following error

    In OnContanctExecutionCompleteMethod, got this error at line

    IEnumerable<new_ustest> response = query.EndExecute(result);

    try
    {
    tataconContext Ctx = new tataconContext(new Uri("https://XXX.crm.dynamics.com/XRMServices/2011/OrganizationData.svc/"));
    
    Ctx.SendingRequest2 += Ctx_SendingRequest2;
    var query = from contact in Ctx.new_ustestSet select contact;
    //var query = from c in Ctx.ContactSet    
    FedId.Instance.SecurityToken.SessionCookieHeader;
    //var container= new OdataReference
    ((DataServiceQuery<new_ustest>)query).BeginExecute(onContanctExecuteComplete, query);
    TxtResults.Text = string.Empty;
    }
    catch (Exception ex)
    {
     TxtResults.Text = ex.Message;
    }
    private void onContanctExecuteComplete(IAsyncResult result)
            {
    
                try
                {
    
                    var query = result.AsyncState as DataServiceQuery<new_ustest>;
                    IEnumerable<new_ustest> response = query.EndExecute(result);
    
    
                    foreach (new_ustest c in response)
                    {
                        TxtResults.Text += c.new_US_Name;
                    }
                }
                catch (Exception ex)
                {
                    TxtResults.Text = ex.Message;
                }
    
    
    
            }
    
            void Ctx_SendingRequest2(object sender, SendingRequest2EventArgs e)
            {
    
                e.RequestMessage.SetHeader(HttpRequestHeader.Cookie.ToString(), FedId.Instance.SecurityToken.SessionCookieHeader);
                e.RequestMessage.SetHeader("ContentType", "application/json;odata=verbose;charset=utf-8");
    
                // throw new NotImplementedException();
            }
    Could some one let me know where Am I going wrong


    Thanks & Regards Tejaswi Chandrapatla

    Tuesday, October 28, 2014 2:49 PM