将 ADO.NET 数据服务和自定义 ServiceContract 合并在同一个类中?

发布于 2024-12-08 01:32:34 字数 875 浏览 0 评论 0原文

我有一个通过 WCF 运行的 ADO.NET 数据服务:

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

我想向其中添加一些自定义方法,例如以下合同

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

如果我添加装饰并在数据服务上实现该方法,则在以下情况下会引发错误客户端尝试连接,并询问:

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

是否无法将服务契约添加到 ADO.NET 数据服务上?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱冒险 2024-12-15 01:32:34

该错误表明该服务公开了多个契约(接口),这是事实,因为您刚刚添加了一个新契约。主机无法再基于隐式默认值工作,因为它不知道在哪个端点上托管哪个服务接口。

确保在服务配置文件中为服务实现的每个合约定义了显式端点。之后,事情将再次开始为您工作,尽管您可能需要在进行修改后更新客户端应用程序中的服务引用。

更新:结合如何禁用身份验证WCF 数据服务方案 告诉您如何使用 http://www.west-wind.com/weblog/posts/2008/Apr/10/WCF-REST-Configuration-for-ASPNET-AJAX-and-plain-REST-Services 进行故障排除您的具体错误消息存在问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文