简体   繁体   中英

ASP.NET Boilerplate WebApi methods

I'm trying to get to work my project on ASP.NET Boilerplate.

I'm right now creating Dynamic Web API and here is what I have:

My AppService:

public interface IBorrowLendAppService : IApplicationService
{
    GetBorrowLendsOutput GetBorrowLends(GetBorrowLendsInput input);
}

My Input:

public class GetBorrowLendsInput : IInputDto
{
    public byte ItemType { get; set; }
    public int PersonId { get; set; }
}

And here's my problem:

  • How to invoke this method?
  • How can I create GET/POST methods (there's no info about it in Boilerplate docs)

When I'm invoking a method [GET]GetBorrowLends without any data I'm receiving error:

{
    "result": null,
    "success": false,
    "error": {
        "code": 0,
        "message": "Your request is not valid!",
        "details": null,
        "validationErrors": [
            {
                "message": "input is null!",
                "members": [
                    "input"
                ]
            }
        ]
    },
    "unAuthorizedRequest": false
}

When I'm trying to invoke it like:

.../GetBorrowLends?ItemType=0&PersonId=1

I'm receiving same error

Invoking [POST] with data:

{
  "input":{
            "ItemType":"0",
            "PersonId":"1" 
          }
}

Returning another error:

{
    "result": null,
    "success": false,
    "error": {
        "code": 0,
        "message": "An internal error occured during your request!",
        "details": null,
        "validationErrors": null
    },
    "unAuthorizedRequest": false
}

How do I handle that? And how to create GET/POST methods manually?

Thanks

Edit:

I have handled problem with not working endpoint. I have wrongly set 'Content-Type' parameter in POST message.

But question about GET/POST methods in ApplicationService is still open.

The default HttpVerb is set to Post.

/// <summary>
/// Default HTTP verb if not set.
/// </summary>
private const HttpVerb DefaultVerb = HttpVerb.Post;

Then there is a method in IApiControllerActionBuilder to change the verb of an action.

IApiControllerActionBuilder<T> WithVerb(HttpVerb verb);

You should be able to change the verb with the following call (in Initialize of your WebAPI module)

DynamicApiControllerBuilder
    .For<ITaskAppService>("tasksystem/taskService")
    .ForMethod("SomeMethod").WithVerb(HttpVerb.Get)
    .Build();

Further information could be obtained on the website .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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