lundi 2 décembre 2019

Exception on attempting to update/delete entities through odata ws

I have built an asp.net web api to consume data from a Microsoft Dynamics Navision OData v4 uri. When I attempt to retrieve a single entity through the context the following ODataException is thrown:

When writing a JSON response, a user model must be specified and the entity set and entity type must be passed to the ODataMessageWriter.CreateODataResourceWriter method or the ODataResourceSerializationInfo must be set on the ODataResource or ODataResourceSet that is being written.'

Example illustrative code:

        public void Delete(string Name)
        {
            NAV.NAV nav = new NAV.NAV(new Uri("http:servername/db/ODataV4/Company"));
            nav.Credentials = CredentialCache.DefaultNetworkCredentials;
            NAV.Customer custToDel = nav.Customer.Where(c => c.Name == Name).First(); //the line of the exception
        }

Posting this question after going through the partly inconsistent/discontinuous odata documentation and lack of intricate knowledge on the protocol. Please let me know for any further information needed that I did not include. Thanks!




Aucun commentaire:

Enregistrer un commentaire