简体   繁体   English

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

[英]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.

相关问题 如何在我的 JSF web 应用程序中拥有 AJAX 功能? - How can I have AJAX functionality in my JSF web application? 我如何在Google Map API Web中创建onclick按钮 - How i create onclick button in my google map api web 为什么我不能使用Javascript访问WCF Web服务? - Why can't I access my WCF web service with Javascript? 如何通过html和JavaScript创建Web服务功能 - How can I create web service functionality via html and JavaScript 我想用 api 中的一个替换我的本地阵列,同时在 javascript 中保持相同的功能。 我怎样才能做到这一点? - I would like to replace my local array with one from an api whilst keeping the same functionality in javascript. How can I achieve this? 如何使用 google map api 加载带有当前地址的地图 - How can I load map with my current address by using google map api 我如何在Jersey Jersey REST Web服务中使用Google OAuth2 - How can i use google OAuth2 in my Jersey REST Web Service 如何在我的脚本(例如googlemap)中创建抓取功能 - How can I create a grabbing functionality in my script like googlemap 如何在REST API中使用fetch? - How can I use fetch with REST API? 如何制作简单的互动式网络地图(比google Chart API允许的更大) - how can I make a simple interactive web map (bigger than what google Chart API allows)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM