HardCode
HardCode

Reputation: 2025

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!

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

Anyone have solution for this?

Upvotes: 2

Views: 1477

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564413

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.

Upvotes: 1

Related Questions