locked
Access is denied where using Sys.Data.DataService RRS feed

  • Question

  •  

    I tried the quick start: how to: Query a Data Service using AJAX,

    http://quickstarts.asp.net/3-5-extensions/adonetdataservice/QueryDataServiceAndAJAX.aspx

     

    It works fine when the client and server is in the same solution.

     

    If I separate the client from the server, it keeps give me the message:

    Access is denied.

     

    The exception is happened in:

    MicrosoftAjax.js

    function Sys$Net$XMLHttpExecutor$executeRequest()

    this._xmlHttpRequest.open(verb, this._webRequest.getResolvedUrl(), true /*async*/);

     

    Here is my server side setting:

    config.SetResourceContainerAccessRule("*", ResourceContainerRights.All);

    config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);

     

    The only thing I changed in the client site is:

    var northwindService = new Sys.Data.DataService(http://localhost:1041/Northwind.svc);

     

    Could anyone please tell me what is wrong?

     

    Thanks!

    Monday, February 4, 2008 2:31 PM

Answers

  • Hi,

     It's not a restriction with the script that prevents you from going Cross Domain.

     MicrosoftAjaxDataService.js uses Sys.Net.WebRequest which in turn uses XmlHttp internally.

     Please refer to this documentation about Native Xmlhttp on MSDN.

     About Native XMLHTTP

    Hope this helps.

     

    Tuesday, February 5, 2008 5:03 PM
    Moderator

All replies

  • Hi,

     The reason you are seeing an Access Denied at this line is because IE does not allow you to make XmlHttP calls to a domain other than the one the current page is running in .

    Since you moved your Data Service from the solution , I would assume that it runs from a different domain .

    ex:

    If Webpage runs in

    http://foo.com/Client

    and Service runs in

    http://Foo.com/Services

    then you are doing a cross domain access.

    There are a couple of ways to resolve this .

    a) Write your own server-side proxy which will run in the same domain as the client and will forward requests to the Data Service.

    b) Move the Data Service back to the Same Domain as the client

    c) Change the Data Services access from XMlhttp ( i.e using AJax Libraries ) to Server-Side (i.e using the LINQ Client ).

     

    Hope this helps.

     

    -Phani

     

    Tuesday, February 5, 2008 12:53 AM
    Moderator
  • Hi Phani,

     

    Thank you so much for your response. It is very helpful.

     

    In a real world enterprise development, we usually separate data service layer from the client view layer, some time from business logic layer, so multiple clients (web, windows), some time different layers, can use the same data service. I do hope these clients can include the JavaScript cross different domains.

     

    An interesting thing is that I can do a cross domain access the data service by using ActiveXObject("Msxml2.XMLHTTP"). If so, why not MicrosoftAjaxDataService.js?

     

    Maybe it is already included in the next version?

     

    Thanks!!

     

    Tuesday, February 5, 2008 3:40 PM
  • Hi,

     It's not a restriction with the script that prevents you from going Cross Domain.

     MicrosoftAjaxDataService.js uses Sys.Net.WebRequest which in turn uses XmlHttp internally.

     Please refer to this documentation about Native Xmlhttp on MSDN.

     About Native XMLHTTP

    Hope this helps.

     

    Tuesday, February 5, 2008 5:03 PM
    Moderator
  • Hello Phani,

    I'm facing the same problem.
    Could you please point to a source where I can find some information on how to
    create a  server-side proxy that will forward requests (a option).
    This is the only suitable solution for me,
    but I unfortunately I was unable to find some helpful information on this topic.

    Sorry if the question is off topic.

    Thanks for your help,
    Alexey.
    Thursday, April 24, 2008 4:37 PM
  •  

    Hi Alexey ,

     Here are some links about server-side proxies to get around cross-domain issues.

     

    http://ajaxpatterns.org/Cross-Domain_Proxy

    http://dotnetslackers.com/columns/ajax/MashitUpwithASPNETAJAX.aspx

     

    Hope this helps.

    -Phani

    Friday, April 25, 2008 2:27 AM
    Moderator