【发布时间】:2012-02-12 16:42:09
【问题描述】:
我正在编写 WCF webapi 应用程序,并且需要检查电子邮件地址是否被占用。这需要是客户端代码在尝试 PUT 之前可以执行的查询。
所以,我正在尝试将HEAD 与 HTTP 状态代码结合使用。我有点不确定如何去做,因为这是一个简单的是/否响应,这是必需的。所以,我用HttpResponseExceptions返回了相关的状态码。
[WebInvoke(Method = "HEAD", UriTemplate = "{email}")]
[RequireAuthorisation]
public void IsEmailAddressTaken(string email)
{
if (!Regex.IsMatch(email, Regexes.EmailPattern))
{
throw new RestValidationFailureException("email", "invalid email address");
}
if (_repository.IsEmailAddressTaken(email))
{
throw new HttpResponseException(HttpStatusCode.OK);
}
throw new HttpResponseException(HttpStatusCode.NoContent);
}
这对我来说并不“闻起来”。
我是否会以正确的方式进行这种是/否操作?
【问题讨论】:
标签: wcf-web-api