WCF Data Service Operation returns collection of the same object
-
18-10-2022 - |
Question
I am using WCF Data Service 5.0 (v3) with EF 4. Below my configuration with one operation "GetProducts":
public static void InitializeService(DataServiceConfiguration config)
{
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.UseVerboseErrors = true;
config.SetServiceOperationAccessRule("GetProducts", ServiceOperationRights.All);
}
Suppose my Entity Data Model has a class [Product] with fields [Id] as integer and [Price] as decimal. My WCF DataService Operation should returns a collection of [Product] objects.
[WebGet]
public IQueryable<Product> GetProducts()
{
var productList = new List<Product>();
//add 4 Products with different Price
productList.Add(new Product { Price = 50.00m });
productList.Add(new Product{ Price = 333 });
productList.Add(new Product{ Price = 2255 });
productList.Add(new Product{ Price = 55.7m });
return productList.AsQueryable();
}
My WCF operation should return 4 objects and each object should have different price. Then I call WCF operation on my client side (WinForms app/.Net 4.0). But on the client side I have a 4 the same objects collection with the same price (price from last object).
What could be causing this behavior?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow