locked
WCF Data Services consuming question RRS feed

  • Question

  • I have a VST2010 solution consisting of 4 projects (layers): Xyz.Infrastructure, Xyz.Domain, Xyz.UserInterface and Xyz.Application.
    In Xyz.Infrastructure I created my ADO Entity Data Model (and some other stuff), in Xyz.Domain I have my POCO's, in Xyz.UserInterface my html (no webforms) with Ajax Client Library and in Xyz.Application my WCF Data Service.

    I have a problem trying to consume my WCF Data Service (in Xyz.Application) from index.htm in my Xyz.UserInterface. The error messae I get when runing my index.htm is can not find the service (see code snippet in index.html hereunder). I can imagine it has to do that MyService.svc is in another project (Xyz.Application), but what should i do that my index.htm finds this service?

    - What is the solution to sove this problem having separate projects (as I have)?
    - Or is the recommended way to have the WCF Data Service in the same project as the index.htm (Xyz.UserInterface) and other UI stuff?

    ...
    dataContext =
    new Sys.Data.OpenDataServiceProxy("MyService.svc");
    dataContext.query(
    "/Customers", ..., ..., ...);
    ...

    Thanks.
    Guy

    Tuesday, June 1, 2010 11:15 AM

Answers

  • Hi,

    It might be due to cross-domain issues, but I'm not sure. You could use Fiddler (www.fiddler2.com) to see what requests you really make and what responses come back (or if the request was even initiated). Also the error itself would be interesting.

    Also obviously the http://localhost will only work on the machine where the IIS is running the service. You need to use the true URL of the server from all other devices.

    Thanks,


    Vitek Karas [MSFT]
    Wednesday, June 2, 2010 8:56 AM
    Moderator

All replies

  • Hi,

    Well this depends on the paths on the server (your web application and the HTML user interface). If you start both the application and the UI, you should be able to see the addresses to both the index.html and the service. Since they are different projects I would assume they will live in different folders on the server/IIS so you might need to tweak your path somewhat.

    Also, what is the Sys.Data.OpenDataServiceProxy class - does it derive from DataServiceContext? If so and there's no URI magic in its constructor, you will need to pass in an absolute URI as far as I know.

    Thanks,


    Vitek Karas [MSFT]
    Tuesday, June 1, 2010 11:32 AM
    Moderator
  • As far as Sys.Data.OpenDataServiceProxy class concerns its part of the Ajax Client Library: http://www.asp.net/ajaxlibrary/Print.aspx?Page=odata.

    Well yes indeed they're (Xyz.Application and Xyz.UserInterface, ...) in different folders. For the moment during development I work with the built-in development VST web server.

    Thanks.
    Guy

    Tuesday, June 1, 2010 1:07 PM
  • Hi,

    Sorry I didn't really this is in java script (not C#).

    You might need to provide a relative URI, something like "../Xyz.Application/Myservice.svc".

    Thanks,


    Vitek Karas [MSFT]
    Tuesday, June 1, 2010 1:29 PM
    Moderator
  • Hi,

    I made real IIS sites (and not Cassini dev web server sites) of the Xyz.Application and Xyz.UserInterface projects. And changed the URI to the complete address (http://localhost/Xyz.Application/MyService.svc). When running index.htm (Xyz.UserInterface project) in a browser on my laptop calling the WCF Data Service (in Xyz.Application project) this works BUT when trying to do the same from a different device (eg smartphone) it doesn't work (data is not coming back from the WCF Data Service).

    I added the WCF Data Service to my Xyz.UserInterface project and then it works (both on my local laptop as well as from a remote device (smartphone). Has this to do with cross-domain Ajax requests (what is not normally allowed)??

    Thanks.

     

    Tuesday, June 1, 2010 4:24 PM
  • Hi,

    It might be due to cross-domain issues, but I'm not sure. You could use Fiddler (www.fiddler2.com) to see what requests you really make and what responses come back (or if the request was even initiated). Also the error itself would be interesting.

    Also obviously the http://localhost will only work on the machine where the IIS is running the service. You need to use the true URL of the server from all other devices.

    Thanks,


    Vitek Karas [MSFT]
    Wednesday, June 2, 2010 8:56 AM
    Moderator