Client-side call to a WCF DataService [WebGet] function

entity-framework odata stored-procedures wcf


I have an EF4 model with a stored procedure that I want to call from the client. The server code looks like this:

public IQueryable<SalesData> GetSalesReport(int reportType, int yr, int m, int d)
    DateTime dt = new DateTime(yr, m, d);
    return this.CurrentDataSource.RP_SalesReport(reportType, dt, dt).AsQueryable<SalesData>();

When calling this using IE using the URL "http://localhost:12345/MyService.svc/GetSalesReport?reportType=1&yr=2009&m=4&d=2" it works as expected.

In my client application I added a reference to the Service (http://localhost:12345/MyService.svc) and whetever I have tried, the function "GetSalesReport" does not show up in the object browser. (Normal EF entities does show up in the object browser)

So my question is: How do I call this function from the Client ?

And is there a difference on how to call this function depending on the client (I want to call this function from a Windows Phone 7 Silverlight App, but right now I am testing using a WPF test client).

1/11/2011 5:19:34 PM

Popular Answer

Actually it looks like the ADO.NET DataTeam hasn't implemented CodeGen for calling a ServiceMethod from the client.

So the soloution to my problem is to write this code at the client:

        // execute the service operation
        Uri u = new Uri(string.Format("{0}/GetSalesReport?reportType={1}&yr={2}&m={3}&d={4}", 
                      context.BaseUri, 1, 2009, 4, 2),UriKind.RelativeOrAbsolute);

        var datas = context.Execute<SalesData>(u);

Thanks to Gil Fink that wrote this Blog post:

1/12/2011 9:46:06 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow