views:

122

answers:

2

I am connecting to an ODATA Service via a C# ASP.NET application, which has service operations such as:

GetItems(int? itemID, double? price)

I can consume this without issues in my browser, e.g.

http://api.mycompany.com/companycatalogue/GetItems?itemID=4

I understand how to use LINQ to Entities to consume an ODATA service, but can't find a decent explanation of how to consume service operations like the one above in C#. I have made a web reference to the service in my Visual Studio solution.

So far, I have something like this for my usual consuming of the data:

using CompanyCatalogue; //my web reference
...
protected void Page_Load(object sender, EventArgs e)
{
    CompanyCatalogueEntities dataContext = new CompanyCatalogueEntities (new Uri("http://api.mycompany.com/companycatalogue/"));
    var result = from i in dataContext.Items select i;  //just an example

    //this is where I get into problems
    var operationResults = CompanyCatalogue.GetItems(6, 20.5); //I just made this up
}

Any pointers?

A: 

Have you tried using HttpWebRequest?

Darrel Miller
Do you mean, using the url and parsing the output?
Zac
@Zac Yes. Alternatively, you can use HTTPClient from the WCF REST Starter Kit, it will do all the heavy lifting for you. Even deserializing into strong types.
Darrel Miller
A: 

OK, got the answer:

using CompanyCatalogue; //my web reference
...
protected void Page_Load(object sender, EventArgs e)
{
    CompanyCatalogueEntities db = new CompanyCatalogueEntities(); 
    var q = from i in db.GetItems(6, 20.5)
            select i; 
}
Zac