locked
Service operation RRS feed

  • Question

  • i am trying to provide a service operation that return an IEnumerable<entitytype>. when i try to run the operation i get this issue.

    The server encountered an error processing the request. The exception message is 'Service operation 'GetBlogPostByTitle' produces instances of type 'Blogs.BlogPost', but there are no visible entity sets for that type. The service operation should be hidden or a resource set for type 'Blogs.BlogPost' should be made visible.'. See server logs for more details. The exception stack trace is:

     

    // This method is called only once to initialize service-wide policies.

     

     

    public static void InitializeService(IDataServiceConfiguration config)
    {
          config.UseVerboseErrors =
    true;
          config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
    }

    [

     

    WebGet]
    public IQueryable<BlogPost> GetBlogPostByTitle(string PostTitle){
    return (from p in this.CurrentDataSource.Posts where p.Title == PostTitle select p).AsQueryable();
    }

    Friday, April 2, 2010 3:19 PM

Answers

  • Hi,

    A Service Operation cannot return an Entity type from an Entity Set that is not exposed via the EntitySetRights.

    Change your IntializeService to look like this :

    public static void InitializeService(IDataServiceConfiguration config)
    {
          config.UseVerboseErrors =
    true
    ;
          config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
          config.SetServiceOperationAccessRule("*", ServiceOperationRights
    .All);
    }


    Phani Raj Astoria http://blogs.msdn.com/PhaniRaj
    Friday, April 2, 2010 4:59 PM
    Moderator

All replies

  • Hi,

    A Service Operation cannot return an Entity type from an Entity Set that is not exposed via the EntitySetRights.

    Change your IntializeService to look like this :

    public static void InitializeService(IDataServiceConfiguration config)
    {
          config.UseVerboseErrors =
    true
    ;
          config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
          config.SetServiceOperationAccessRule("*", ServiceOperationRights
    .All);
    }


    Phani Raj Astoria http://blogs.msdn.com/PhaniRaj
    Friday, April 2, 2010 4:59 PM
    Moderator
  • Hi Man ,

    Please make sure you have changed the access rules for enitites you are exposing. Set the access rule to EntitySetRights.All  for all the entities . Such that you can perfrom all the CRUD operations for entities.


    Thanks Dhananjay Kumar
    MVP Connected System Developer http://dhananjaykumar.net/
    Contact: dhananjay.kumar@ust-global.com Twitter: http://twitter.com/dhananjay_k
    Monday, April 5, 2010 5:07 AM