Syntax to call an oData Method?

11 posts, 0 answers
  1. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 16 Oct 2011 Link to this post

    How do I call an odata method?

    This is what I need to call
    http://odata.site.com/USDA.svc/GetNutritionalInfo?ndbno=1001&seq=107&servingsize=1

    Works though fiddler, however the kendo DS is appending these $format=json&$inlinecount=allpages&$callback=callback which is throwing a error 400 bad request.

    Looks like if I remove this parameter fiddler, it returns the proper value
    "$inlinecount=allpages"

    How can I prevent that from being passed?
  2. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 17 Oct 2011 Link to this post

    Hello Steve,

    Could you please verify that the OData service is V2 compatible. For example if you are using WCF DataService the following line does exists in the InitializeService:

    config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;

    Also you may enable the verbose errors to see more detail description of the error you are getting.All the best,
    Rosen
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 17 Oct 2011 Link to this post

    Ok, I'll enable Verbose...I am running V2 though

    using System;
    using System.Collections.Generic;
    using System.Data.Objects;
    using System.Data.Services;
    using System.Data.Services.Common;
    using System.Linq;
    using System.ServiceModel.Web;
    using System.Web;
    using DataServicesJSONP;
     
    namespace My.oData
    {
        [JSONPSupportBehavior]
        public class USDA : DataService<MyEntities>
        {
            // This method is called only once to initialize service-wide policies.
            public static void InitializeService(DataServiceConfiguration config)
            {
                config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
                //Set a reasonable paging site
                config.SetEntitySetPageSize("*", 25);
     
                config.SetServiceOperationAccessRule("GetNutritionalInfo", ServiceOperationRights.AllRead);
                config.SetServiceOperationAccessRule("TestMethod", ServiceOperationRights.All);
     
                //config.UseVerboseErrors = true;
                config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
            }
     
            protected override void OnStartProcessingRequest(ProcessRequestArgs args)
            {
                base.OnStartProcessingRequest(args);
     
                HttpCachePolicy c = HttpContext.Current.Response.Cache;
                c.SetCacheability(HttpCacheability.ServerAndPrivate);
                c.SetExpires(HttpContext.Current.Timestamp.AddSeconds(60));
                c.VaryByHeaders["Accept"] = true;
                c.VaryByHeaders["Accept-Charset"] = true;
                c.VaryByHeaders["Accept-Encoding"] = true;
                c.VaryByParams["*"] = true;
            }
     
            [WebInvoke(Method = "POST")]
            [WebGet]
            public getFoodNutritionalInfo_Result GetNutritionalInfo(int ndbno, double servingsize, int seq)
            {
                MyEntities entities = newMyEntities();
                ObjectResult<getFoodNutritionalInfo_Result> result = entities.getFoodNutritionalInfo(ndbno, servingsize, seq);
     
                return result.FirstOrDefault();
            }
     
            [WebInvoke(Method = "POST")]
            [WebGet]
            public bool TestMethod()
            {
                return true;
            }
        }
    }

    So even calling "TestMethod" fails with the KendoDS...and it does nothing but return true
  5. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 17 Oct 2011 Link to this post

    This is the Verbose error

    callback({
    "error": {
    "code": "", "message": {
    "lang": "en-US", "value": "Query options $expand, $filter, $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource."
    }
    }
    })

    ...so how do I stop the DS applying it?
  6. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 18 Oct 2011 Link to this post

    Hello Steve,

    The error you are getting is cause by the fact that the parameters are applicable only for methods which return IEnumerable. However, your method returns a plaint type instead, which also is not valid binding for our DataSource too. The DataSource expects some kind of array to be received from the server.

    All the best,
    Rosen
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  7. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 18 Oct 2011 Link to this post

    Changing it to ObjectResult<> or IEnumerable<> directly yields the exact same error

    [WebInvoke(Method = "POST")]
            [WebGet]
            public IEnumerable<getFoodNutritionalInfo_Result> GetNutritionalInfo(int ndbno, double servingsize, int seq)
            {
                GourmetSleuthEntities entities = new GourmetSleuthEntities();
                ObjectResult<getFoodNutritionalInfo_Result> result = entities.getFoodNutritionalInfo(ndbno, servingsize, seq);
     
                return result;
            }

    [WebInvoke(Method = "POST")]
            [WebGet]
            public ObjectResult<getFoodNutritionalInfo_Result> GetNutritionalInfo(int ndbno, double servingsize, int seq)
            {
                GourmetSleuthEntities entities = new GourmetSleuthEntities();
                ObjectResult<getFoodNutritionalInfo_Result> result = entities.getFoodNutritionalInfo(ndbno, servingsize, seq);
     
                return result;
            }
  8. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 19 Oct 2011 Link to this post

    Hi Steve,

    Unfortunately, I'm unable to recreate the behavior locally, therefore could you please provide a small sample in which this can be observed locally.

    All the best,
    Rosen
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  9. Grace
    Grace avatar
    2 posts
    Member since:
    Jan 2012

    Posted 13 Jan 2012 Link to this post

    Hi Steve,

    Did you resolve this issue? I'm getting the same behavior and looking for a resolution. Thanks!
  10. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 13 Jan 2012 Link to this post

    Yes, I think in another forum thread, when I get home I'll post the snippit, but I think off the top of my head I just didn't use oData as the type but instead jsonp
  11. Grace
    Grace avatar
    2 posts
    Member since:
    Jan 2012

    Posted 13 Jan 2012 Link to this post

    Oh thank you! That'd be wonderful.
  12. Courouble Damien
    Courouble Damien avatar
    54 posts
    Member since:
    Aug 2009

    Posted 17 May 2012 Link to this post

    Would like to give us your code ? I'm facing similar issue here !

    Thanks
Back to Top
Kendo UI is VS 2017 Ready