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 74,115 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans