繁体   English   中英

如何将此WCF功能映射到我的REST Web API?

[英]How can I map this WCF functionality to my REST web api?

问候我有一个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);

我让用户基本上做同样的事情,但是在客户端。

我已经创建了一个看起来像这样的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;
}

因此,当我输入网址时,会在控制台中看到以下内容:

{"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."}

我的问题是我需要做什么,以便用户可以键入dToBook类的属性,然后进行POST并添加书。 我猜现在它只是尝试添加它而没有任何属性。

任何帮助都值得赞赏

尝试指定方法为post,例如:

[HttpPost]
public HttpResponseMessage Add([FromBody]List<DtoBook> Books)
{
   // code
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM