0

I'm converting a project that uses WCF to WebApi. AsyncCallback objects can easily be passed on as if it's a normal method call. However, when trying to deserialize the result in my .NET Core WebApi, it produces errors.

public class AsyncRequest {
[JsonConstructor]
public AsyncRequest () {}
public AsyncCallback Callback { get; set; }
}

// The object is being used in methods like this:
[HttpPost]
[Route("action")]
public IActionResult Action ([FromBody]AsyncRequest request) {
}

I have several other WebApi methods working, including with objects to send information. So it's not an issue with WebApi in general.

MrFox
  • 4,852
  • 7
  • 45
  • 81
  • What's the error you got? You could try to [adding `NewtonsoftJson`](https://stackoverflow.com/a/59649201/13655939) in `ConfigureServices`. – Michael Wang Sep 23 '20 at 08:15
  • @MichaelWang Value cannot be null. (Parameter 'method'), looking at the JSON it does have such a paramter, but with property name "method0", so it looks like they have different serialization/deserialization methods. – MrFox Sep 28 '20 at 07:57
  • @MichaelWang When I replace that in the JSON with "method" it produces the error "member 'value' was not found". – MrFox Sep 28 '20 at 08:23
  • Hi, @MrFox, without the Json and the completed object, I can't see the error. I suggest you check the json you post via JSON formatter & Validator and deserialize object properties which is same from JSON string. – Michael Wang Sep 28 '20 at 09:24

1 Answers1

0

These callbacks are how async methods are implemented in WCF.
Since we're now using WebApi all calls are async by default.
So this implementation is no longer needed.

MrFox
  • 4,852
  • 7
  • 45
  • 81