Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Interacting with a Page Web Service (OData v4) Error

Interacting with a Page Web Service (OData v4) Error

Scheduled Pinned Locked Moved C#
csharphelpasp-netsysadminsales
20 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MaWeRic
    wrote on last edited by
    #1

    Hi! I have published a Microsoft Dynamics NAV page as an OData web service V4. I used Odata v4 Client Code Genrator ver 2.4.0 to create the Client side proxy classes for my C# project. When I make a simple call to "myhost/.../Company" everything works like a charm using simple code like this:

    NAVCient = new NAVEntities.NAV(new Uri("myhost/.../ODataV4"));
    NAVCient.Credentials = new Net.NetworkCredential("usr", "psw");
    List company = NAVCient.Company.ToList;

    I get my list of available Companies. Now I want to get the CustomerCards for my selected Company. I do like this:

    NAVCient = new NAVEntities.NAV(new Uri("myhost/.../ODataV4/Company('MyTest')"));
    NAVCient.Credentials = new Net.NetworkCredential("usr", "psw");
    List Customers = NAVCient.Customer_Card.ToList;

    The uri genrated is correct and I can see the response comming back correct using fiddler with all my data. Code gets an exception trying to parse the information. At first i thought the backend had some issues but clearly its the client producing this error bec in fiddler I can see my result and nothing else as a response from server :

    "An unhandled exception of type 'Microsoft.OData.Core.ODataException' occurred in Microsoft.OData.Core.dll
    Additional information: When writing a JSON response, a user model must be specified and the entity set and entity type must be passed to the ODataMessageWriter.CreateODataEntryWriter method or the ODataFeedAndEntrySerializationInfo must be set on the ODataEntry or ODataFeed that is being written."

    Any suggestions/advice? I have tried other sources and they work as it seem. Thanks for your help // henrik Tags:

    L 1 Reply Last reply
    0
    • M MaWeRic

      Hi! I have published a Microsoft Dynamics NAV page as an OData web service V4. I used Odata v4 Client Code Genrator ver 2.4.0 to create the Client side proxy classes for my C# project. When I make a simple call to "myhost/.../Company" everything works like a charm using simple code like this:

      NAVCient = new NAVEntities.NAV(new Uri("myhost/.../ODataV4"));
      NAVCient.Credentials = new Net.NetworkCredential("usr", "psw");
      List company = NAVCient.Company.ToList;

      I get my list of available Companies. Now I want to get the CustomerCards for my selected Company. I do like this:

      NAVCient = new NAVEntities.NAV(new Uri("myhost/.../ODataV4/Company('MyTest')"));
      NAVCient.Credentials = new Net.NetworkCredential("usr", "psw");
      List Customers = NAVCient.Customer_Card.ToList;

      The uri genrated is correct and I can see the response comming back correct using fiddler with all my data. Code gets an exception trying to parse the information. At first i thought the backend had some issues but clearly its the client producing this error bec in fiddler I can see my result and nothing else as a response from server :

      "An unhandled exception of type 'Microsoft.OData.Core.ODataException' occurred in Microsoft.OData.Core.dll
      Additional information: When writing a JSON response, a user model must be specified and the entity set and entity type must be passed to the ODataMessageWriter.CreateODataEntryWriter method or the ODataFeedAndEntrySerializationInfo must be set on the ODataEntry or ODataFeed that is being written."

      Any suggestions/advice? I have tried other sources and they work as it seem. Thanks for your help // henrik Tags:

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You haven't said specifically which statement is failing. I would try:

      var Customers = NAVCient.Customer_Card;
      ... = Customers.ToList();
      etc.

      instead of:

      List Customers = NAVCient.Customer_Card.ToList;

      And see how far I get from there.

      "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

      M 1 Reply Last reply
      0
      • L Lost User

        You haven't said specifically which statement is failing. I would try:

        var Customers = NAVCient.Customer_Card;
        ... = Customers.ToList();
        etc.

        instead of:

        List Customers = NAVCient.Customer_Card.ToList;

        And see how far I get from there.

        "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

        M Offline
        M Offline
        MaWeRic
        wrote on last edited by
        #3

        It is failing on the .ToList part ... Its very wierd. Tried that thing but same. And wierdest of all why is it trying to write a JSON-response? Sounds more like something from server?

        L 1 Reply Last reply
        0
        • M MaWeRic

          It is failing on the .ToList part ... Its very wierd. Tried that thing but same. And wierdest of all why is it trying to write a JSON-response? Sounds more like something from server?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          That was the point. Inspect the "var" using the debugger before performing the "ToList" and see what you're getting versus what you're expecting.

          "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

          M 2 Replies Last reply
          0
          • L Lost User

            That was the point. Inspect the "var" using the debugger before performing the "ToList" and see what you're getting versus what you're expecting.

            "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

            M Offline
            M Offline
            MaWeRic
            wrote on last edited by
            #5

            Will take a look into it ... Getting back to you!

            1 Reply Last reply
            0
            • L Lost User

              That was the point. Inspect the "var" using the debugger before performing the "ToList" and see what you're getting versus what you're expecting.

              "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

              M Offline
              M Offline
              MaWeRic
              wrote on last edited by
              #6

              The object returned is :

              Microsoft.OData.Client.DataServiceQuery(Of Customer_Card)

              The object created by the Client generator. I need to call .Execute or something else with collection to make it execute the query. If I do that I get :

              Microsoft.OData.Client.QueryOperationResponse(Of Customer\_Card)	
              

              The execution seem ok. Problem is when I start enumerating through the list that shold have been produced. I can clearly see in fiddler that result comming back to me is ok. Something is happening on clientside. Maybe the call itself to the service is doing something wierd. But why should it do that when it works on the query for Company. Can this has to do with child/relations spec maybe? Thanks ZD

              L 1 Reply Last reply
              0
              • M MaWeRic

                The object returned is :

                Microsoft.OData.Client.DataServiceQuery(Of Customer_Card)

                The object created by the Client generator. I need to call .Execute or something else with collection to make it execute the query. If I do that I get :

                Microsoft.OData.Client.QueryOperationResponse(Of Customer\_Card)	
                

                The execution seem ok. Problem is when I start enumerating through the list that shold have been produced. I can clearly see in fiddler that result comming back to me is ok. Something is happening on clientside. Maybe the call itself to the service is doing something wierd. But why should it do that when it works on the query for Company. Can this has to do with child/relations spec maybe? Thanks ZD

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                You say execution "seems ok" .... Hardly a show of confidence. Instead of assuming it is "ok", there are a number of properties in the response you should look at (e.g. "Error") to confirm that everything is as it should be. [QueryOperationResponse Class (System.Data.Services.Client)](https://msdn.microsoft.com/en-us/library/system.data.services.client.queryoperationresponse(v=vs.113).aspx)

                "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                M 1 Reply Last reply
                0
                • L Lost User

                  You say execution "seems ok" .... Hardly a show of confidence. Instead of assuming it is "ok", there are a number of properties in the response you should look at (e.g. "Error") to confirm that everything is as it should be. [QueryOperationResponse Class (System.Data.Services.Client)](https://msdn.microsoft.com/en-us/library/system.data.services.client.queryoperationresponse(v=vs.113).aspx)

                  "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                  M Offline
                  M Offline
                  MaWeRic
                  wrote on last edited by
                  #8

                  Trying executing .Execute on the object of type :

                  Global.Microsoft.OData.Client.DataServiceQuery(Of Customer_Card)

                  Gives me this object and I can see in fiddler that response is received and correct but accoring to error TotalCount is missing: https://postimg.org/image/eyv1hglnj/ However I got the objext I am supposed to. If I try to call .ToList it first makes call to .Execute and then try to create :

                  System.Collections.Generic.List(Of NAVEntities.Customer_Card)

                  But it produces an error and I the object looking like this: https://postimg.org/image/e3ewt9b5j/ Full stacktrace is:

                  Microsoft.OData.Core.ODataException was unhandled
                  HResult=-2146233079
                  Message=When writing a JSON response, a user model must be specified and the entity set and entity type must be passed to the ODataMessageWriter.CreateODataEntryWriter method or the
                  ODataFeedAndEntrySerializationInfo must be set on the ODataEntry or ODataFeed that is being written.
                  Source=Microsoft.OData.Core
                  StackTrace:
                  at Microsoft.OData.Core.ODataFeedAndEntryTypeContext.ValidateAndReturn[T](T value)
                  at Microsoft.OData.Core.ODataFeedAndEntryTypeContext.get_NavigationSourceName()
                  at Microsoft.OData.Core.Evaluation.ODataConventionalEntityMetadataBuilder.ComputeId()
                  at Microsoft.OData.Core.Evaluation.ODataConventionalEntityMetadataBuilder.ComputeAndCacheId()
                  at Microsoft.OData.Core.Evaluation.ODataConventionalEntityMetadataBuilder.GetId()
                  at Microsoft.OData.Client.Materialization.MaterializerEntry.UpdateEntityDescriptor()
                  at Microsoft.OData.Client.Materialization.FeedAndEntryMaterializerAdapter.ReadEntryCore()
                  at Microsoft.OData.Client.Materialization.FeedAndEntryMaterializerAdapter.TryReadEntry(MaterializerEntry& entry)
                  at Microsoft.OData.Client.Materialization.FeedAndEntryMaterializerAdapter.d__0.MoveNext()
                  at Microsoft.OData.Client.Materialization.FeedAndEntryMaterializerAdapter.Read()
                  at Microsoft.OData.Client.Materialization.ODataReaderEntityMaterializer.ReadNextFeedOrEntry()
                  at Microsoft.OData.Client.Materialization.ODataEntityMaterializer.ReadImplementation()
                  at Microsoft.OData.Client.MaterializeAtom.MoveNextInternal()
                  at Microsoft.OData.Client.MaterializeAtom.MoveNext()
                  at System.Linq.Enumerable.d__94`1.MoveNext()
                  at System.Collections.Generic

                  L 1 Reply Last reply
                  0
                  • M MaWeRic

                    Trying executing .Execute on the object of type :

                    Global.Microsoft.OData.Client.DataServiceQuery(Of Customer_Card)

                    Gives me this object and I can see in fiddler that response is received and correct but accoring to error TotalCount is missing: https://postimg.org/image/eyv1hglnj/ However I got the objext I am supposed to. If I try to call .ToList it first makes call to .Execute and then try to create :

                    System.Collections.Generic.List(Of NAVEntities.Customer_Card)

                    But it produces an error and I the object looking like this: https://postimg.org/image/e3ewt9b5j/ Full stacktrace is:

                    Microsoft.OData.Core.ODataException was unhandled
                    HResult=-2146233079
                    Message=When writing a JSON response, a user model must be specified and the entity set and entity type must be passed to the ODataMessageWriter.CreateODataEntryWriter method or the
                    ODataFeedAndEntrySerializationInfo must be set on the ODataEntry or ODataFeed that is being written.
                    Source=Microsoft.OData.Core
                    StackTrace:
                    at Microsoft.OData.Core.ODataFeedAndEntryTypeContext.ValidateAndReturn[T](T value)
                    at Microsoft.OData.Core.ODataFeedAndEntryTypeContext.get_NavigationSourceName()
                    at Microsoft.OData.Core.Evaluation.ODataConventionalEntityMetadataBuilder.ComputeId()
                    at Microsoft.OData.Core.Evaluation.ODataConventionalEntityMetadataBuilder.ComputeAndCacheId()
                    at Microsoft.OData.Core.Evaluation.ODataConventionalEntityMetadataBuilder.GetId()
                    at Microsoft.OData.Client.Materialization.MaterializerEntry.UpdateEntityDescriptor()
                    at Microsoft.OData.Client.Materialization.FeedAndEntryMaterializerAdapter.ReadEntryCore()
                    at Microsoft.OData.Client.Materialization.FeedAndEntryMaterializerAdapter.TryReadEntry(MaterializerEntry& entry)
                    at Microsoft.OData.Client.Materialization.FeedAndEntryMaterializerAdapter.d__0.MoveNext()
                    at Microsoft.OData.Client.Materialization.FeedAndEntryMaterializerAdapter.Read()
                    at Microsoft.OData.Client.Materialization.ODataReaderEntityMaterializer.ReadNextFeedOrEntry()
                    at Microsoft.OData.Client.Materialization.ODataEntityMaterializer.ReadImplementation()
                    at Microsoft.OData.Client.MaterializeAtom.MoveNextInternal()
                    at Microsoft.OData.Client.MaterializeAtom.MoveNext()
                    at System.Linq.Enumerable.d__94`1.MoveNext()
                    at System.Collections.Generic

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    Unfortunately, you're posting "code fragments"; which makes it hard to discern what you are or are not doing. You previously hinted it might be a "relation" thing; yes, data services does "lazy loading"; cannot tell from your post if you addressed this. [How to: Load Related Entities (WCF Data Services)](https://msdn.microsoft.com/en-us/library/dd756366(v=vs.110).aspx)

                    "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                    M 1 Reply Last reply
                    0
                    • L Lost User

                      Unfortunately, you're posting "code fragments"; which makes it hard to discern what you are or are not doing. You previously hinted it might be a "relation" thing; yes, data services does "lazy loading"; cannot tell from your post if you addressed this. [How to: Load Related Entities (WCF Data Services)](https://msdn.microsoft.com/en-us/library/dd756366(v=vs.110).aspx)

                      "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                      M Offline
                      M Offline
                      MaWeRic
                      wrote on last edited by
                      #10

                      Lets see if I can put up a sample thing for you. Yes lazyloading might be a thing just like in EF. Need to turn it off maybe? Thanks // zd

                      M L 2 Replies Last reply
                      0
                      • M MaWeRic

                        Lets see if I can put up a sample thing for you. Yes lazyloading might be a thing just like in EF. Need to turn it off maybe? Thanks // zd

                        M Offline
                        M Offline
                        MaWeRic
                        wrote on last edited by
                        #11

                        Cant see anything in fiddler that draws me into that relation-direction. Its just plain-data. Have to dive deeper into that.

                        Z 1 Reply Last reply
                        0
                        • M MaWeRic

                          Lets see if I can put up a sample thing for you. Yes lazyloading might be a thing just like in EF. Need to turn it off maybe? Thanks // zd

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #12

                          Perhaps only using a Browser for now will help to clarify what is going on: [Accessing the Service from a Web Browser (WCF Data Services Quickstart)](https://msdn.microsoft.com/en-us/library/dd728279(v=vs.110).aspx) I suggest you try it.

                          "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                          M 2 Replies Last reply
                          0
                          • M MaWeRic

                            Cant see anything in fiddler that draws me into that relation-direction. Its just plain-data. Have to dive deeper into that.

                            Z Offline
                            Z Offline
                            zequion
                            wrote on last edited by
                            #13

                            I'm thinking the possibility that from Main () can access its copy of Name_Common to do Name_Common.Cls_Common.StCommon = new Name_Common.St_Common(); For now I do not know how to do it because there is an error. So when I want to use a class, I can copy Main's global structure to that of the class. I have remembered that I did a function to make (cast) of one estrcuture to another one. For now I can not make new Name_Common.St_Common(); of Main(). The brain has stopped me for days. I can also someone something about points 2 and 3 of debugger employment? Thank you.

                            P 1 Reply Last reply
                            0
                            • Z zequion

                              I'm thinking the possibility that from Main () can access its copy of Name_Common to do Name_Common.Cls_Common.StCommon = new Name_Common.St_Common(); For now I do not know how to do it because there is an error. So when I want to use a class, I can copy Main's global structure to that of the class. I have remembered that I did a function to make (cast) of one estrcuture to another one. For now I can not make new Name_Common.St_Common(); of Main(). The brain has stopped me for days. I can also someone something about points 2 and 3 of debugger employment? Thank you.

                              P Offline
                              P Offline
                              Pete OHanlon
                              wrote on last edited by
                              #14

                              What has this got to do with this question? Please don't hijack others posts.

                              This space for rent

                              1 Reply Last reply
                              0
                              • L Lost User

                                Perhaps only using a Browser for now will help to clarify what is going on: [Accessing the Service from a Web Browser (WCF Data Services Quickstart)](https://msdn.microsoft.com/en-us/library/dd728279(v=vs.110).aspx) I suggest you try it.

                                "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                                M Offline
                                M Offline
                                MaWeRic
                                wrote on last edited by
                                #15

                                I am on to it ... Getting back ... //zd

                                1 Reply Last reply
                                0
                                • L Lost User

                                  Perhaps only using a Browser for now will help to clarify what is going on: [Accessing the Service from a Web Browser (WCF Data Services Quickstart)](https://msdn.microsoft.com/en-us/library/dd728279(v=vs.110).aspx) I suggest you try it.

                                  "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                                  M Offline
                                  M Offline
                                  MaWeRic
                                  wrote on last edited by
                                  #16

                                  Everything ok with browsing the service. Filtering etc work like a charm. This is for sure client-issue. I have tried to generate proxyclasses using 2 different tools that state they can produce proxy for OData v4. If I try to use Add Service Reference I get en error like this :

                                  Quote:

                                  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 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).'. - was not expected. If the service is defined in the current solution, try building the solution and adding the service reference again.

                                  Guess That built in proxyclass generator only handles up to V3? This is what my Schema look like:

                                  Thanks

                                  L 1 Reply Last reply
                                  0
                                  • M MaWeRic

                                    Everything ok with browsing the service. Filtering etc work like a charm. This is for sure client-issue. I have tried to generate proxyclasses using 2 different tools that state they can produce proxy for OData v4. If I try to use Add Service Reference I get en error like this :

                                    Quote:

                                    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 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).'. - was not expected. If the service is defined in the current solution, try building the solution and adding the service reference again.

                                    Guess That built in proxyclass generator only handles up to V3? This is what my Schema look like:

                                    Thanks

                                    L Offline
                                    L Offline
                                    Lost User
                                    wrote on last edited by
                                    #17

                                    Yes; when your previously mentioned you used a "generator" .... It's almost a given you will have less control and less transparency. I usually go "down to the metal" first time around; and then I MAY go "fancy". [OData - the Best Way to REST](http://www.odata.org/) [Home · object/Simple.OData.Client Wiki · GitHub](https://github.com/object/Simple.OData.Client/wiki)

                                    "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                                    M 1 Reply Last reply
                                    0
                                    • L Lost User

                                      Yes; when your previously mentioned you used a "generator" .... It's almost a given you will have less control and less transparency. I usually go "down to the metal" first time around; and then I MAY go "fancy". [OData - the Best Way to REST](http://www.odata.org/) [Home · object/Simple.OData.Client Wiki · GitHub](https://github.com/object/Simple.OData.Client/wiki)

                                      "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                                      M Offline
                                      M Offline
                                      MaWeRic
                                      wrote on last edited by
                                      #18

                                      Thanks Gerry ... yes I dont like it either but client wanted an easy way to code against Microsoft Dynamics. I have been all over that Odata-site and everything work as intended if you do it the raw way, I do like the look of Simple.OData.Client. Maybe try it out. Have you tested it? We are sending in the question to NAV developement team to see if they have any answer to why it dont work with a generator. Thanks for all your help ;)

                                      L 1 Reply Last reply
                                      0
                                      • M MaWeRic

                                        Thanks Gerry ... yes I dont like it either but client wanted an easy way to code against Microsoft Dynamics. I have been all over that Odata-site and everything work as intended if you do it the raw way, I do like the look of Simple.OData.Client. Maybe try it out. Have you tested it? We are sending in the question to NAV developement team to see if they have any answer to why it dont work with a generator. Thanks for all your help ;)

                                        L Offline
                                        L Offline
                                        Lost User
                                        wrote on last edited by
                                        #19

                                        You're welcome. No, I haven't tried "Simple.OData.Client"; but it has a good "smell". But if your "raw" methods are working, I wouldn't bother. I also wouldn't bother NAV. I would instead consider spending time giving the client an "attitude adjustment".

                                        "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                                        M 1 Reply Last reply
                                        0
                                        • L Lost User

                                          You're welcome. No, I haven't tried "Simple.OData.Client"; but it has a good "smell". But if your "raw" methods are working, I wouldn't bother. I also wouldn't bother NAV. I would instead consider spending time giving the client an "attitude adjustment".

                                          "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                                          M Offline
                                          M Offline
                                          MaWeRic
                                          wrote on last edited by
                                          #20

                                          We are on the same level ;) I try out the Simple Client. I love the smell too. //ZD

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups