Reputation: 1347
I'm using a working sample Odata service http://services.odata.org/v3/(S(ttgz0nndpwaj2eahro3jq0xt))/odata/odata.svc/
I did the following steps: create console application -> add service reference -> put the URL -> go -> then I saw the service with all the entities (like product suppliers etc) -> press OK and put the following code. Assuming I want to get the product data, how should I do that?
I use the following code to get the data, but without success, any idea ? (I guess I should call on the service proxy that was generated but I'm not sure how...)
One additional question : suppose the service has basic authentication and I need to provide a username and a password, how should I do that?
OdataService.Product Client = new OdataService.Product();
// Query the weather information.
var Output = from ThisData
in Client.Products
select ThisData;
Console.WriteLine(Output.ToString());
Console.ReadLine();
This is the URL http://services.odata.org/v3/(S(ttgz0nndpwaj2eahro3jq0xt))/odata/odata.svc/Products
Upvotes: 0
Views: 1060
Reputation: 5465
You're trying to create an instance of the Product rather than an instance of the service proxy. You can create an instance of OdataService and you have to pass in the Url of the service. This should work:
var service = new OdataService(new Uri("http://services.odata.org/v3/(S(ttgz0nndpwaj2eahro3jq0xt))/odata/odata.svc"));
service.Credentials = CredentialCache.DefaultNetworkCredentials; // Set your credentials here if you need to
var products = service.Products.ToList(); // Gives a list of products
Upvotes: 1