【发布时间】:2013-08-03 04:28:43
【问题描述】:
我正在开发 WCF 休息服务,我的 ServiceContract 上有这个:
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "/users",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
User AddOrUpdateUser(User user);
[OperationContract]
[WebInvoke(Method = "PUT",
UriTemplate = "/users",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
User AddOrUpdateUser(User user);
我将使用User AddOrUpdateUser(User user); 到POST 和PUT:
public User AddOrUpdateUser(User user)
{
if (user == null)
throw new ArgumentNullException("user", "AddOrUpdateUser: user is null");
using (var context = new AdnLineContext())
{
context.Entry(user).State = user.UserId == 0 ?
EntityState.Added :
EntityState.Modified;
context.SaveChanges();
}
return user;
}
我正在关注这个pattern 来做这件事。
但是,我得到一个错误:
The type 'MyCompanyWCFService.IMyCompanyService' already contains a definition for
'AddOrUpdateUser' with the same parameters
我该如何解决这个问题?
【问题讨论】:
-
这可以通过以下帖子加倍,看看是否有帮助:stackoverflow.com/questions/555073/…
-
您是否尝试过将两个
WebInvoke属性放在同一个方法上?