locked
EF + WCF + ASP.NET AJAX RRS feed

  • Question

  • How to use Entity Framework with WCF service and ASP.NET AJAX? Now I have service with WebHttpBinding and it works, but when I share some entity I have error on page.
    "Microsoft JScript - błąd czasu wykonywania: Sys.Net.WebServiceFailedException: The server method 'GetAllCities' failed with the following error: "


    All works fine using WsHttpBinding.

     

    Tuesday, July 8, 2008 7:13 AM

Answers

  • Slawek,

    This was the subject of another recent thread in the forums:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3586838&SiteID=1

    The case is that the full graph serialization feature required to serialize Entity Framework classes is not compatible with DataContractJsonSerializer. It works well XML serialization though.

    In the thread above the customer mentioned that he found a workaround: use JavaScriptSerializer for serialization and DataContractJsonSerializer only for deserialization. I haven’t tried this myself.

    Another suggestion I can make is to use ADO.NET Data Services (a.k.a. Astoria). The bits are included in VS 2008 SP1 beta. ADO.NET Data Services support Json.

    Hope this helps,
    Diego

    Wednesday, July 9, 2008 8:01 AM

All replies

  • Slawek,

    Isn’t there anything else after “the following error:”?

    Thanks,
    Diego

    Tuesday, July 8, 2008 3:07 PM
  • No but when I made method GetAllCitiesAsJson and use DataContractJsonSerializer the following exception:
    ArgumentException:

    Encountered unexpected prefix 'z'. The prefix must be null or empty.

    Nazwa parametru: prefix

    Tuesday, July 8, 2008 5:49 PM
  • Slawek,

    This was the subject of another recent thread in the forums:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3586838&SiteID=1

    The case is that the full graph serialization feature required to serialize Entity Framework classes is not compatible with DataContractJsonSerializer. It works well XML serialization though.

    In the thread above the customer mentioned that he found a workaround: use JavaScriptSerializer for serialization and DataContractJsonSerializer only for deserialization. I haven’t tried this myself.

    Another suggestion I can make is to use ADO.NET Data Services (a.k.a. Astoria). The bits are included in VS 2008 SP1 beta. ADO.NET Data Services support Json.

    Hope this helps,
    Diego

    Wednesday, July 9, 2008 8:01 AM