locked
Consuming a service operation from .net client give me an error. RRS feed

  • Question

  • 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);
        }
    
    


    Wednesday, August 22, 2012 9:36 AM

Answers

  • Hi,

    The DataServiceQuery is itself a queryable, so the T for it is the item type (not the entire query type). So in the code above use DataServiceQuery<MyEntity> q = CreateQuery<MyEntityt>("MyOperation") ....

    If the MyEntity is really an entity, then you don't need to get rid of the parenthesis, and should be able to execute the query by executing the DataServiceQuery itself (not going through the Execute method).

    Thanks,


    Vitek Karas [MSFT]

    Wednesday, August 22, 2012 12:35 PM
    Moderator

All replies

  • Hi,

    The DataServiceQuery is itself a queryable, so the T for it is the item type (not the entire query type). So in the code above use DataServiceQuery<MyEntity> q = CreateQuery<MyEntityt>("MyOperation") ....

    If the MyEntity is really an entity, then you don't need to get rid of the parenthesis, and should be able to execute the query by executing the DataServiceQuery itself (not going through the Execute method).

    Thanks,


    Vitek Karas [MSFT]

    Wednesday, August 22, 2012 12:35 PM
    Moderator
  • You are right. It works. Thanks.
    Thursday, August 23, 2012 9:00 AM