Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

NAV 2017, OData, C#

(1) ShareShare
ReportReport
Posted on by 8
Hi Community,
 
My goal is to create a C# Console App with Visual Studio 2019 for calling NAV 2017 OData API.
I have generated the proxy with OData Connected Service.
 
I have a first snippet which works fine :
var context = new NAV(new Uri(serviceRoot));
context.Credentials = new NetworkCredential(/mylogin/, /mypassword/);
var nbCarriers = context.Transporteurs.Count();
Console.WriteLine(/Number of Carriers:/ + nbCarriers);
 
 
I have an error with a second snippet :
var context = new NAV(new Uri(serviceRoot));
context.Credentials = new NetworkCredential(/mylogin/, /mypassword/);
var myCarriers = context.Transporteurs.Execute();
foreach (var myCarrier in myCarriers) {  Console.WriteLine(/{0} {1}/, myCarrier.Name, myCarrier.Code); }
 
Microsoft.OData.ODataException : '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.'
 
I have tried to find somme resources about this problem via Google but I can't find a good solution.
Can you hlep me, please?
 
  • Newbie_13 Profile Picture
    Newbie_13 8 on at
    NAV 2017, OData, C#
    Hi Yun!
    I didn't kow this Postman feature.
    Many thanks for your help, you've saved my week^^.
  • Verified answer
    YUN ZHU Profile Picture
    YUN ZHU 75,848 Super User 2024 Season 2 on at
    NAV 2017, OData, C#
    Hi, sorry, this may not be a good example, you can generate some sample code through Postman.
     
    Hope this can give you some hints.
    Thanks.
    ZHU

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans