[英]How can I map this WCF functionality to my REST web api?
Greetings I have a WCF service, and basically what the API users do to create a book is following: 问候我有一个WCF服务,基本上API用户要做的是以下几本书:
var Book = new DtoBook()
{
OpenInModal = false,
CallToActionUrl = "url"
Status = NotificationStatus.Unseen,
TimeStamp = DateTime.Now,
Type = NotificationType.Type,
Message = "test,
};
BookManager.Instance.Add(Book);
I have users to basically do the same thing but instead on the client-side. 我让用户基本上做同样的事情,但是在客户端。
I have created a POST method already that looks like this: 我已经创建了一个看起来像这样的POST方法:
public HttpResponseMessage Add(List<DtoBook> Books)
{
if (!ModelState.IsValid)
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
BookManager.Instance.Add(Books);
var response = Request.CreateResponse(HttpStatusCode.Created, Books);
return response;
}
So when I enter the url I get following in my console: 因此,当我输入网址时,会在控制台中看到以下内容:
{"Message":"The request is invalid.","MessageDetail":"The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.String Get(Int32)' in 'test.Controllers.NotificationsController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter."}
My question is what do I need to do so the user can type the properties of the dToBook class and then the POST happens and the book gets added. 我的问题是我需要做什么,以便用户可以键入dToBook类的属性,然后进行POST并添加书。 I guess right now it just tries to add it without any properties.
我猜现在它只是尝试添加它而没有任何属性。
Any kind of help is appreciated 任何帮助都值得赞赏
Try to specify the method is post, for sample: 尝试指定方法为post,例如:
[HttpPost]
public HttpResponseMessage Add([FromBody]List<DtoBook> Books)
{
// code
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.