简体   繁体   中英

Entity Framework GET Web Service Throwing Errors

I have this GREAT WCF service that returns Data from EF.

public class HistoryDataService : DataService<HistoryEntities>
{
    #region Public Methods

    public static void InitializeService(DataServiceConfiguration config)
    {
        config.SetEntitySetAccessRule("*", EntitySetRights.All);
        config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
    }

    [WebGet]
    public IQueryable<History> GetHistoriesById(int recordId)
    {
        return CurrentDataSource.Histories.Where(d => d.RecordId == recordId);
    }

    #endregion
}

I have other services that I added something like:

[WebGet(UriTemplate = "eventdetails/{id}", ResponseFormat = WebMessageFormat.Json)] 

to make it more of a traditional RESTful service, however, when I add it I get various errors like:

... both defines a ServiceContract and inherits a ServiceContract from type System.Data.Services.IRequestHandler.`  

How do I add this property or is it even possible?

It would save you a lot of time to use WCF Data Services or OData as it is called. You'll get both JSON and XML output for your web service response. Your choice. : )

WCF Data Services

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