Reputation: 803
If I consume my service operation from the browser, it works perfectly.
If I consume my service operation from .net client, it gives me an error
"The type 'System.Linq.IQueryable`1[MyEntity]' has no settable properties."
Any idea? Thanks.
Client code:
public IQueryable<MyEntity> CallMyOperation(string param1 = "", string param2 = "") {
DataServiceQuery<IQueryable<MyEntity>> q =
CreateQuery<IQueryable<MyEntity>>("MyOperation")
.AddQueryOption("param1", "'" + param1 + "'")
.AddQueryOption("param2", "'" + param2 + "'");
return
Execute<IQueryable<MyEntity>>(
new Uri(q.RequestUri.ToString().Replace("MyOperation()", "MyOperation"))).
FirstOrDefault();
}
Wcf Service code:
[WebGet]
public IQueryable<MyEntity> MyOperation(string param1 = "", string param2 = "") {
...
}
public static void InitializeService(DataServiceConfiguration config) {
config.DataServiceBehavior.MaxProtocolVersion =
DataServiceProtocolVersion.V3;
config.UseVerboseErrors = true;
config.SetEntitySetAccessRule("MyEntity", EntitySetRights.AllRead);
config.SetServiceOperationAccessRule("MyOperation", ServiceOperationRights.AllRead);
}
Upvotes: 2
Views: 1275
Reputation: 4336
The call to Execute<T>
should just have the generic type you want materialized, not an IQueryable<T>
. When the materialization process runs, it tries to set properties on the object from the entities it received in the WebResponse
. Since IQueryable<T>
doesn't have the properties you're getting back on the wire, materialization fails.
If you still want an IQueryable
, you can call Execute<MyEntity>(...).AsQueryable()
.
Upvotes: 2