web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

What is the recommended way of consuming a NAV OData webservice v4 using .NET

(0) ShareShare
ReportReport
Posted on by

Hi!

I have published a Microsoft Dynamics NAV page as an OData web service V4.

We have tried numerious client proxy genereators including the ones published by Microsoft (Odata v4 Client Code Generator ver 2.4.0) and nothing seem to work.

Now we wonder what Microsoft NAV Team recommend when it comes to consuming the service. Any steps/tutorials/samplecode(c# or vb.net) would be greatly appreciated.
Thanks //
Henrik

*This post is locked for comments

I have the same question (1)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,278 Super User 2026 Season 1 on at

    Please check this blog

    www.archerpoint.com/.../consuming-nav-2013-page-using-c-and-odata

  • Community Member Profile Picture
    on at

    Your example is prov Odata 1 or something. V4 dont work with Add Service Reference as it seem to me. If I try I get this error :

    The document at the url file:///e:/client.xml was not recognized as a known document type.
    The error message from each known type may help you fix the problem:
    - Report from 'XML Schema' is 'The root element of a W3C XML Schema should be <schema> and its namespace should be 'http://www.w3.org/2001/XMLSchema'.'.
    - Report from 'DISCO Document' is 'Discovery document at the URL file:///e:/client.xml could not be found.'.
      - The document format is not recognized.
    - Report from 'WSDL Document' is 'There is an error in XML document (2, 2).'.
      - <Edmx xmlns='http://docs.oasis-open.org/odata/ns/edmx'> was not expected.


    Any thoughts?

  • Suggested answer
    Suresh Kulla Profile Picture
    50,278 Super User 2026 Season 1 on at

    Which page have you published ? what is the url you are using ?

  • Community Member Profile Picture
    on at

    We have published everything.

    Url to the metadocument is this : 

    http://thehost:7058/nav17livews/odatav4/$metadata


    Document look like below (the start)

    edmx:Edmx xmlns:edmx="docs.oasis-open.org/.../edmx" Version="4.0">
    <edmx:DataServices>
    <Schema xmlns="docs.oasis-open.org/.../edm" Namespace="NAV">
    <EntityType Name="Accounting_Periods">
  • Suggested answer
    Suresh Kulla Profile Picture
    50,278 Super User 2026 Season 1 on at

    Are you using this URL thehost/.../odatav4$metadata when you add to the service reference ?  

    you need to use thehost/.../OData

  • Community Member Profile Picture
    on at

    That is not a metadocument?

  • Community Member Profile Picture
    on at

    Trying to use that with Client Proxy Generator for Odata v4 gives me:

    Severity	Code	Description	Project	File	Line	Suppression State
    Error		Running transformation: System.Xml.XmlException: Root element is missing.
       at System.Xml.XmlTextReaderImpl.Throw(Exception e)
       at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
       at System.Xml.XmlTextReaderImpl.Read()
       at System.Xml.XmlReader.MoveToContent()
       at System.Xml.Linq.XElement.Load(XmlReader reader, LoadOptions options)
       at System.Xml.Linq.XElement.Parse(String text, LoadOptions options)
       at System.Xml.Linq.XElement.Parse(String text)
       at Microsoft.VisualStudio.TextTemplating9C75E0AB9F6D19DBF8364854AEAFBAA5A943565337DA61D507EE5CF3AC07E75E057D01AB48915DE0CDB25B3B11EFC2A9F16F67802022C4CC61781567F3D1D43F.GeneratedTextTransformation.CodeGenerationContext..ctor(String edmx, String namespacePrefix) in :line 560
       at Microsoft.VisualStudio.TextTemplating9C75E0AB9F6D19DBF8364854AEAFBAA5A943565337DA61D507EE5CF3AC07E75E057D01AB48915DE0CDB25B3B11EFC2A9F16F67802022C4CC61781567F3D1D43F.GeneratedTextTransformation.CodeGenerationContext..ctor(Uri metadataUri, String namespacePrefix) in :line 547
       at Microsoft.VisualStudio.TextTemplating9C75E0AB9F6D19DBF8364854AEAFBAA5A943565337DA61D507EE5CF3AC07E75E057D01AB48915DE0CDB25B3B11EFC2A9F16F67802022C4CC61781567F3D1D43F.GeneratedTextTransformation.TransformText() in :line 67			560	


  • Suggested answer
    Suresh Kulla Profile Picture
    50,278 Super User 2026 Season 1 on at

    Znow,

    I have not used client code generator, but i just added the following url as Service Reference in my class library localhost/.../OData which gave me the services available and i have chosen the service.

    Do you need to use Odata Client Code Generator

  • Community Member Profile Picture
    on at

    Hi!

    So you used the built in Add Service Reference in Visual Studio with a OData v4 Service from Nav?

    Can you show me the document you get when surfing to your /Odata? Are you sure this is v4 version and you are using NAV 2017? Its enough with the start of it to verify that we get the same thing.

    I do not need to use the OData Client Proxy Generator if Add Service Reference works. Maybe I need an update of Visual Studio? I am not sure there is one though for this.

    When I surf to my "/Odatv4" i get a document like this :

    {
      "@odata.context":"http://thehost:7058/nav17livews/odatav4/$metadata","value":[
        {
          "name":"Accounting_Periods","kind":"EntitySet","url":"Accounting_Periods"
        },{
          "name":"Apply_Customer_Entries","kind":"EntitySet","url":"Apply_Customer_Entries"
        },{
          "name":"Cash_Receipt_Journal","kind":"EntitySet","url":"Cash_Receipt_Journal"
        },{
          "name":"Chart_Of_Accounts","kind":"EntitySet","url":"Chart_Of_Accounts"
    


    If I surf to

    http://thehost:7058/nav17livews/odatav4/$metadata

    I get:

    <edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
    <edmx:DataServices>
    <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="NAV">
    <EntityType Name="Accounting_Periods">
    <Key>
    <PropertyRef Name="Starting_Date"/>
    </Key>
    <Property Name="Starting_Date" Type="Edm.DateTimeOffset" Nullable="false"


    None of those documents work for me when I add them as Reference and try to generate


    //ZD

  • Suggested answer
    Suresh Kulla Profile Picture
    50,278 Super User 2026 Season 1 on at

    Padon me, but I am not sure how you are referring OData as V4 service of NAV, when I published myservices on NAV they are available on localhost/.../OData so i just used that on my service reference. It is NAV 2017.

    What is specific about ODatav4 and how did you get the url thehost/.../odatav4

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
TAHER_El_Mehdi Profile Picture

TAHER_El_Mehdi 2

#1
sliderxb Profile Picture

sliderxb 2

#1
broberts Profile Picture

broberts 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans