locked
How to consume stored procedure from data services RRS feed

  • Question

  • I'm able to consume the table, both in the browser and the codes.  But for the stored procedure, I only able to invoke it via browser.  I can't bind the data to the grid like the table.  Is there a way to do it with stored procedure.  I have tried many way but could not success. 

    Here is the simple sample that I tried in order to do for bigger things later if success:

    ****My service:

    public

     

     

    class SampleDB : DataService<SampleDBEntities1>

    {

     

     

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

     

     

    public static void InitializeService(DataServiceConfiguration config)

    {

     

     

    // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.

     

     

    // Examples:

    config.SetEntitySetAccessRule(

     

    "*", EntitySetRights.AllRead);

    config.SetServiceOperationAccessRule(

     

    "*", ServiceOperationRights.All);

    config.DataServiceBehavior.MaxProtocolVersion =

     

    DataServiceProtocolVersion.V2;

    }

    [

     

    WebGet]

     

     

    public List<GetAllEmployers_Result>GetAllEmployers()

    {

     

     

    return CurrentDataSource.GetAllEmployers().ToList();

     

    }

    }

     

    ***My client code to consume it:

     

    public

     

     

    partial class _Default : System.Web.UI.Page

    {

     

     

    protected void Page_Load(object sender, EventArgs e)

    {

     

     

    Uri svcURI = new Uri("http://localhost:27664/SampleDB.svc");

     

     

    Uri svcURIOperation = new Uri("http://localhost:27664/SampleDB.svc/GetAllEmployers");

    SampleDBService.

     

    SampleDBEntities1 context = new SampleDBService.SampleDBEntities1(svcURI);

     

     

    //var query = context.Execute<GetAllEmployers_Result>(

     

     

    // new Uri(String.Format("{0}GetAllEmployeers",

     

     

    // context.BaseUri, 0),

     

     

    // uriKind.RelativeOrAbsolute));

     

     

     

     

    IEnumerable<GetAllEmployers_Result> query = context.Execute<GetAllEmployers_Result>(new Uri(http://localhost:27664/SampleDB.svc/GetAllEmployers));

     

     

    gvEmployer.DataSource = query.ToList();

    gvEmployer.DataBind();

    }

    }

     


    Learning Sharepoint
    Thursday, January 13, 2011 7:13 PM

Answers

  • Hi,

    The client library currently doesn't support consuming results of service operations unless the service operation returns a single entity or a list (IEnumerable or IQueryable) of entities. It's not 100% clear from the code above, but I think your service operation returns enumeration of complex types (the GetAllEmployers_Result is a complex type, right?). If that's the case, then this is not currently a supported scenario. You would have to issue that request manually through some HTTP library (WebClient or HttpWebRequest) and parse the response manually (XLinq is probably the easiest).

    Thanks,


    Vitek Karas [MSFT]
    Thursday, January 13, 2011 11:53 PM
    Moderator