3

My WebApi action returns a dynamic object built from JObject.parse(jsonString);

I have GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();

But that object is wrapped inside a default result message in the response.

According to this article returning anonymous objects is fine and should give the expected result

I am using an async controller because I have to await some ReadAsStringAsync() here the protoype of my action:

public async Task<dynamic> Pics(string flavor, int pagesize)

Expected result :

{"flavor":"","maxFeedSize":0,"mediaContent":[]}

Result I have when returning the dynamic object:

{
        "Result": {
            "flavor": "",
            "maxFeedSize": 0,
            "mediaContent": []
        },
        "Id": 1,
        "Exception": null,
        "Status": 5,
        "IsCanceled": false,
        "IsCompleted": true,
        "CreationOptions": 0,
        "AsyncState": null,
        "IsFaulted": false
    }
2
  • I'm unclear what you are asking. What is the behavior you're expecting, and what behavior are you actually getting? Commented Nov 27, 2012 at 1:01
  • 2
    By the looks of things you're getting a serialized Task<dynamic>... can you post all of your controller action code? Commented Nov 27, 2012 at 1:10

1 Answer 1

1

As I thought and as mentioned in comments. I was returning a Task<Task<dynamic>> because of a naive method overload.

    public async Task<dynamic> Pics(string flavor, string pagesize)
    {
        return Pics(flavor, pagesize, null);
    }

Edit: I tried this because unlike MVC routes ommit a string parameter throws an error even if string is nullable

  public async Task<dynamic> Pics(string flavor, string pagesize, string startid =null)

works fine :)

Sign up to request clarification or add additional context in comments.

1 Comment

Or you could make your overload non-async (tip: listen to your compiler warnings). Like this: public Task<dynamic> Pics(string flavor, string pagesize) { return Pics(flavor, pagesize, null); }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.