我是servicestack的新手,不知怎的,我的POST,PUT和DELETE方法都无效。
错误 - ServiceStack.WebException:方法不允许 ErrorCode - NotImplementedException
虽然GET方法按预期工作!
有任何建议我为什么会收到这样的错误。
服务请求代码示例 -
[Route("/students", "POST")]
public class CreateStudent : IReturn<StudentDTO>
{
public int Id { get; set; }
public String FirstName { get; set; }
public string LastName { get; set; }
}
服务响应 -
public StudentDTO Post(CreateStudent request)
{
var student = new Student()
{
Id = request.Id,
FirstName = request.FirstName,
LastName = request.LastName
};
using (var connection = this.OpenDbConnection())
{
connection.Insert(student);
}
return Mapper.Map<StudentDTO>(student);
}
这就是我的称呼方式 -
var student = new Student
{
Id = Guid.NewGuid(),
FirstName = "FirstName",
LastName = "LastName"
};
var response = this.Client.Post(student);
提前致谢!
答案 0 :(得分:2)
您的请求DTO是CreateStudent
,但您发布的是完全不同的Student
DTO,请将其更改为使用请求DTO,例如:
var client = new JsonServiceClient(BaseUrl);
var request = new CreateStudent
{
FirstName = "FirstName",
LastName = "LastName"
};
var response = client.Post(request);