Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

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

Posted on by Microsoft Employee

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

  • star lord Profile Picture
    star lord 25 on at
    RE: What is the recommended way of consuming a NAV OData webservice v4 using .NET

    Hello, can you pls tell me if there is away to fetch metadata of a single service? instead of all services

    Also is it possible to fetch this data in json instead of xml?

    TIA :)

  • Ghetz Profile Picture
    Ghetz 2,983 on at
    RE: What is the recommended way of consuming a NAV OData webservice v4 using .NET

    Totally agree.. this web services seem completely useless. Have not found any tool that will generate a usable proxy. There should be an easy way to consume a Page web service from .net or .net core, but I haven't found any examples.

    Also the metadata page will show hundred web services if you have hundred published. There seems to be no way to reference a single service.

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: What is the recommended way of consuming a NAV OData webservice v4 using .NET

    Hello Cyril,

    I have not used those v4 options but will check into it and let you know but in the meantime I think to get the data in json format you can use format option. Please check below link.

    msdn.microsoft.com/.../dn127071(v=nav.90).aspx

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: What is the recommended way of consuming a NAV OData webservice v4 using .NET

    Hi Suresh,

    Long time no see :-) I am the customer that ZnowDog develops for.

    We want to use V4 as it gives json and not xml for our client apps. You see the url in attached picture and everything works for that service except fetching the data.

    ws_5F00_port.png

    ws_5F00_port.png

    Rgds

    Cyril

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: What is the recommended way of consuming a NAV OData webservice v4 using .NET

    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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: What is the recommended way of consuming a NAV OData webservice v4 using .NET

    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
    Suresh Kulla 43,745 on at
    RE: What is the recommended way of consuming a NAV OData webservice v4 using .NET

    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
    Community Member Microsoft Employee on at
    RE: What is the recommended way of consuming a NAV OData webservice v4 using .NET

    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	


  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: What is the recommended way of consuming a NAV OData webservice v4 using .NET

    That is not a metadocument?

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: What is the recommended way of consuming a NAV OData webservice v4 using .NET

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

    you need to use thehost/.../OData

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 Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans