简体   繁体   English

如何覆盖WCF Resfull服务中的方法?

[英]How do I override a method in WCF Resfull service?

I found a post explain to put 我发现有一篇说明要放

[OperationContract(Name = "GetDataWithNumber")]
public User GetName(int id)

[OperationContract(Name = "GetDataWithString")]
public User GetName(string email)

This wont work if I use Restfull service! 如果我使用Restfull服务,这将无法工作!

[OperationContract(Name = "GetDataWithNumber")]
[WebGet(UriTemplate = "Service/GetName?id={id}", ResponseFormat = WebMessageFormat.Json)]
public User GetName(int id)

Anyone have solution for this? 有人对此有解决方案吗?

I would recommend just using two methods: 我建议仅使用两种方法:

[OperationContract(Name = "GetDataWithNumber")]
public User GetNameFromId(int id)

[OperationContract(Name = "GetDataWithString")]
public User GetNameFromEmail(string email)

This will eliminate the confusion, as well as be more explicit. 这将消除混乱,并且更加明确。 As the REST service is going to be translating from a text-based representation, the explicit nature is very useful in terms of maintainability. 由于REST服务将要从基于文本的表示形式进行翻译,因此在可维护性方面,显式性质非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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