1

I have a Library wrapper OVH API and i try to call a function for get my consumer key in a ASP.NET MVC project. It works in a Console project application but the method never response in my Controller : the method in the Library

public async Task<CredentialsResponse> RequestCredential(IEnumerable<AccessRule> accessRules, string redirectUrl = null)
    {
        Ensure.NotNull("accessRules", accessRules);

        CredentialsRequest cmd = new CredentialsRequest();
        cmd.AccessRules.AddRange(accessRules);
        cmd.Redirection = redirectUrl;

        if (cmd.AccessRules.Count == 0)
            throw new ArgumentException("You must specify at least one accessRule");
        return await RawCall<CredentialsResponse>(HttpMethod.Post, "/auth/credential", cmd;
    }

and i call in the controller :

public ActionResult Index()
    {
        Information infosClient = new Information();

        OvhApiClient api = new OvhApiClient("", "", OvhInfra.Europe);

        CredentialsResponse response = api.RequestCredential(new[]{
            new AccessRule{ Method = "GET", Path = "/*"},
            new AccessRule{ Method = "PUT", Path = "/*"},
            new AccessRule{ Method = "POST", Path = "/*"},
            //new AccessRule{ Method = "DELETE", Path = "/*"},
        }).Result;

        api.ConsumerKey = response.ConsumerKey;

        infosClient.ConsumerKey = api.ConsumerKey;
        return View(infosClient);
    }

I already tried quite a lot of things without success (put the call in a method async for example).

Thanks in advance for your help

1 Answer 1

11

Make the controller action async:

public async Task<ActionResult> Index()
{
    ...
    CredentialsResponse response = await api.RequestCredential(...);
    ...
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yes there was just a delay to validate.

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.