Search code examples
wcfodatadataservice

Simple.Odata.Client Retrieve Data From WCF Dataservice


My wcf dataservice is using self-host,When I tried to retrieve data from wcf dataservice by simploe.odata.client,it throws a error:Internal Server Error. wcf dataservice code:public class RFODataService : DataService<RFODBEntities> { public static void InitializeService(DataServiceConfiguration config) { config.SetEntitySetAccessRule(typeof(DETAIL).Name, EntitySetRights.All); config.SetEntitySetAccessRule(typeof(HEADER).Name, EntitySetRights.All); } }

self-host code:`var currentAssembly = Assembly.GetAssembly(this.GetType()); if (currentAssembly == null) return "Assembly not found"; var types = currentAssembly.GetTypes().Where(w => w.IsClass && w.Namespace.Contains("DataServices")).ToArray();

        for (int i = 0; i < types.Length; i++)
        {
            var svcHost = new DataServiceHost(serviceType, new Uri[] { new Uri(string.Format("http://localhost:{0}/", Port)) });
            svcHost.Open();
        }`

simple.odata.client code:`var client = new ODataClient("URL");

        var detail = client.For("DETAIL").FindEntriesAsync();

        string temp = detail.Result.ToString();

        Console.Write(temp);`

It is trouble me,is there any one know the reason?


Solution

  • Since you are getting InternalServerError it's most probably something with the service implementation or setup. I suggest you first isolate the error by running a query in the browser. Try something like SERVER_URL/Details (I assume you have an entity set called Details) and check the response from the server. If this doesn't work then your problem is the server. If it works, check your Simple.Data.Client queries by running Fiddler and inspecting HTTP traffic. If generated query is different (and wrong) you can open an issue at Simple.OData.Client GitHub site and I can investigate it.