我正在开发 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);
toPOST
和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;
}
我正在遵循这种模式来做到这一点。
但是,我收到一个错误:
The type 'MyCompanyWCFService.IMyCompanyService' already contains a definition for
'AddOrUpdateUser' with the same parameters
我该如何解决这个问题?