locked
SL2B2 Read from EF not working RRS feed

  • Question

  • Hi I am trying the following sample code:

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Net;

    using System.Windows;

    using System.Windows.Controls;

    using System.Windows.Documents;

    using System.Windows.Input;

    using System.Windows.Media;

    using System.Windows.Media.Animation;

    using System.Windows.Shapes;

    using System.Data.Services.Client;

    using NitishTestModel;

    using System.Collections;

    namespace SilverlightApplication1

    {

    public partial class Page : UserControl

    {

    public Page()

    {

    InitializeComponent();

    }

    private void btnClick_Click(object sender, RoutedEventArgs e)

    {

    Entities ctx = new Entities(new Uri("http://localhost:49968/WebDataService1.svc"));

    var qry = from l in ctx.Link2

    where l.ID==1 select l;

    // Cast the query to a DataServiceQuery

    DataServiceQuery<Link2> Link2Query = (DataServiceQuery<Link2>)qry;

    // Start the execution

    Link2Query.BeginExecute(new AsyncCallback(OnLoadComplete),

    Link2Query);

    }

    void OnLoadComplete(IAsyncResult result)

    {

    // Get a reference to the Query

    DataServiceQuery<Link2> Link2Query = (DataServiceQuery<Link2>)result.AsyncState;

    // Get ther esults and add them to the collection

    List<Link2> _lnks = Link2Query.EndExecute(result).ToList();

    }

     

     

    }

    }

    but i get the following error:

    System.InvalidOperationException occurred
      Message="Failed to Invoke: callOpen."
      StackTrace:
           at System.Windows.Browser.ScriptObject.Invoke(String name, Object[] args)
           at System.Data.Services.Http.ScriptObjectUtility.CallOpen(ScriptObject request, String method, String uri)
           at System.Data.Services.Http.HttpWebRequest.ScriptXmlHttpRequest.Open(Boolean async, String url, String method, Action OnReadyStateChange)
           at System.Data.Services.Http.HttpWebRequest.InvokeRequest(Boolean async)
           at System.Data.Services.Http.HttpWebRequest.BeginGetResponse(AsyncCallback callback, Object state)
           at System.Data.Services.Client.QueryAsyncResult.BeginExecute(MemoryStream requestContent)
           at System.Data.Services.Client.DataServiceRequest.BeginExecute(Object source, DataServiceContext context, AsyncCallback callback, Object state)
           at System.Data.Services.Client.DataServiceQuery`1.BeginExecute(AsyncCallback callback, Object state)
           at SilverlightApplication1.Page.btnClick_Click(Object sender, RoutedEventArgs e)
      InnerException:

    Thanks in Advance,

    NJ

    Wednesday, June 11, 2008 1:21 PM

Answers

  • Figured it. It was because of this :-

    "Unfortunately, due to work arounds required for other aspects of Data Services functionality, cross-domain access is not supported in the Data Services client included in Silverlight Beta 2. We're working to sort out the issue for the RTM release.

     

    Pablo Castro
    Software Architect
    Microsoft Corporation
    http://blogs.msdn.com/pablo"

    Pablo Castro's post from the Astoria forum

    Wednesday, June 11, 2008 2:08 PM

All replies

  • Figured it. It was because of this :-

    "Unfortunately, due to work arounds required for other aspects of Data Services functionality, cross-domain access is not supported in the Data Services client included in Silverlight Beta 2. We're working to sort out the issue for the RTM release.

     

    Pablo Castro
    Software Architect
    Microsoft Corporation
    http://blogs.msdn.com/pablo"

    Pablo Castro's post from the Astoria forum

    Wednesday, June 11, 2008 2:08 PM
  • "Unfortunately, due to work arounds required for other aspects of Data Services functionality, cross-domain access is not supported in the Data Services client included in Silverlight Beta 2. We're working to sort out the issue for the RTM release.

    Hi, have you solved for the RC0?

    Thanks

    Friday, October 10, 2008 6:29 AM
  •  Hi,

    This does not seems to be a cross domain problem . Are you having both of your dataservice and webapplication in sam eporject or different project ? 

    Thanks,

    Thani

    Sunday, November 2, 2008 10:16 PM
  •  I have the same problem. I think it's because my dataservice and webapplication are in different projects. It seams to me that it is a cross domain problem. Please help.

    Thanks.

    Tuesday, November 4, 2008 3:19 AM
  • Having dataservice and webapplication in two different projects equival to a crossdomain.

    I read somewhere, sorry I don't have the link right now, that silverlight use the XMLHttpRequest to access the dataservice so has the same limit of Ajax. You have to use a server side proxy.

     PS this is the link: http://blogs.msdn.com/phaniraj/archive/2008/10/21/accessing-cross-domain-ado-net-data-services-from-the-silverlight-client-library.aspx

    Tuesday, November 4, 2008 3:49 AM
  •  Thanks for the link. I have followed that tutorial but I still have a problem : AsyncCallback never returns a result and the CrossDomainHandler class crashes of NullReferenceException because it doesn't receive anything when GetResponseStream() is called. This cross-domain problem becomes a real pain to me. Please help.

    Friday, November 7, 2008 7:23 AM
  • Consuming  ADO.NET Services into Silverlight Application


    Entities context =
    new
    NorthwindEntities(new Uri(HtmlPage.Document.DocumentUri, "Northwind.svc"));

    http://msmvps.com/blogs/theproblemsolver/archive/2009/01/06/consuming-an-ado-net-data-service-from-silverlight.aspx

    Friday, May 29, 2009 2:56 AM