1

我已经使用 WCF 创建了 REST 服务,并且我有不同的合同(合同 1、合同 2 等)。这是中的配置web.config

<endpoint address="users" binding="webHttpBinding" behaviorConfiguration="web" contract="FilmInfoApi.Service.IUserService"/>
    <endpoint address="actors" binding="webHttpBinding" behaviorConfiguration="web" contract="FilmInfoApi.Service.IActorService"/>
    <endpoint address="films" binding="webHttpBinding" behaviorConfiguration="web" contract="FilmInfoApi.Service.IFilmService"/>

这是合同的例子。

[OperationContract]
    [WebGet(UriTemplate = "?offset={offset}&count={count}", ResponseFormat = WebMessageFormat.Json)]
    Films GetFilms(string offset, string count);

所以我的问题是如何为所有端点(localhost/rest)使用相同的地址。因为我需要更灵活的合同 UriTemplate,例如,如果我需要按类别返回电影列表(uri 示例:localhost/rest/category/2)。但是有了这个 uri 和当前配置( web.config 中的address 属性),我必须将此方法放入 Category 合同中。但在我看来,这种方法必须在电影合同中。那么它有解决方案还是正常?

4

1 回答 1

1

如果您想使用单个端点公开多个合同,那么您必须让其中一个合同从另一个合同继承。然后让您的端点公开派生合同。如下所示:

[ServiceContract]
IFilmService : IActorService

然后有一个端点:

<endpoint address="rest" binding="webHttpBinding" behaviorConfiguration="web" contract="FilmInfoApi.Service.IFilmService"/>
于 2013-10-07T04:43:45.903 回答