There is a service on WCF. Must perform the role of a REST service.

There is a book.

[DataContract] public class Book { [DataMember] public int BookId { get; set; } [DataMember] public string Title { get; set; } [DataMember] public string ISBN { get; set; } } 

There is an add book interface.

  [OperationContract] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "AddBook/{id}")] string AddBook(Book newBook, string id); 

The method of this interface.

  public string AddBook(Book newBook, string id) { //Book newBook = repository.AddNewBook(book); if (book == null) return "id = " + id;//newBook.BookId; else return "asd" + book; } 

GET, DELETE requests pass with a bang. With POST problems. Promise

Answer 200. But I get that the object is empty. enter image description here

  • So you transmit the data as Form Data, and the service expects Json. - Primus Singularis
  • I’m sending this {"BookId": 1, "ISBN": "123456", "Title": "First"}. The answer is 200. But I get that the object is null. - Vasya Makarchuk

1 answer 1

Solved. In the interface description you had to use

 BodyStyle = WebMessageBodyStyle.Bare