Combine ADO.NET Data Service and custom ServiceContract in the same class?

梦想的初衷 提交于 2019-12-12 12:22:18

问题


I have an ADO.NET Data service that I run through WCF:

public class AdminService : DataService<BOPApplicationAccessEntities> {        
    public static void InitializeService(DataServiceConfiguration config) {
            config.UseVerboseErrors = true;
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
            config.SetEntitySetAccessRule("*", EntitySetRights.All);
        }
}

I'd like to add some custom methods to it, such as the following contract

[ServiceContract]
    public interface IAdminService {
        [OperationContract]
        void RequestAccess(int applicationID, string username);
    }

If I add the decoration and implement the method on the data service, an error is thrown when a client tries to connect, saying:

AdminService implements multiple servicecontract types, and no endpoints are defined in the configuration file.

Is it not possible to add service contracts onto an ADO.NET data services service?


回答1:


The error states that the service exposes multiple contracts (interfaces), which is true, because you just added a new one. The host is not able to work based on implicit default values anymore, because it does not know which service interface to host on which endpoint.

Make sure you have an explicit endpoint defined in your service configuration file for each contract your service implements. Thing will start to work for you again after that, though you might need to update the service reference in your client application after making the modifications.

Update: Combine How to disable authentication schemes for WCF Data Services which tells how to explicitly create an endpoint for your WCF Data Service with http://www.west-wind.com/weblog/posts/2008/Apr/10/WCF-REST-Configuration-for-ASPNET-AJAX-and-plain-REST-Services to troubleshoot problems with your specific error message.



来源:https://stackoverflow.com/questions/7649832/combine-ado-net-data-service-and-custom-servicecontract-in-the-same-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!