简体   繁体   中英

In WCF Data Services, how can I limit the entities visible to the consumer?

My Init method looks like this

public static void InitializeService(DataServiceConfiguration config)
{
    config.UseVerboseErrors = true;
    config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
    config.SetServiceOperationAccessRule("*", ServiceOperationRights.AllRead);
    config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}

However, I know there is a way to limit the client from seeing the 100 entities in my data model. I only want to expose four! Maybe the Init() methods has nothing to do with it. How do you do it?

You can remove the line

 config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);

and replace it with setting the desired access on your individual entity sets.
Example here: MSDN: DataServiceConfiguration.SetEntitySetAccessRule Method

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM