JJoe123
JJoe123

Reputation: 71

ServiceStack POST,PUT, DELETE method not working

I am newbie to servicestack and somehow my POST,PUT and DELETE methods are not working.

Error - ServiceStack.WebException: Method Not Allowed ErrorCode - NotImplementedException

Though the GET method is working as expected!

Any suggestion why am I getting such error.

Service Request Code Sample -

[Route("/students", "POST")]
public class CreateStudent : IReturn<StudentDTO>
{
    public int Id { get; set; }
    public String FirstName { get; set; }
    public string LastName { get; set; }
}

Service Response -

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);
    }

This is how I am calling it -

var student = new Student
        {
            Id = Guid.NewGuid(),
            FirstName = "FirstName",
            LastName = "LastName"
        };

        var response = this.Client.Post(student);

Thanks In Advance!

Upvotes: 1

Views: 1155

Answers (1)

mythz
mythz

Reputation: 143319

Your Request DTO is CreateStudent but you're posting a completely different Student DTO, change it to use the Request DTO, e.g:

var client = new JsonServiceClient(BaseUrl);

var request = new CreateStudent
{
    FirstName = "FirstName",
    LastName = "LastName"
};

var response = client.Post(request);

Upvotes: 2

Related Questions