asp.net-mvcapiconsole-applicationblockcypher

Accsing an API from console is working but same is not working with MVC web


I am trying to access BlockCypher from console Application which works absolutely fine. But when i am trying to access the same MVC Web Application, I am not getting the response from "BlockCypher". not sure why. here is the link i am following:

BlockCypher git

here is the code i am using

  Blockcypher objmain = new Blockcypher("XXXXXXXXXXXXXXX", Endpoint.BcyTest);

        objmain.GenerateAddress().Wait();

please help, any idea what i am doing wrong in web.? or what i am missing.


Solution

  • You seem to be hitting a deadlock, instead of using Wait() in a synchronous context, instead make your action / parent code async and use await.

    public async Task<ActionResult> MyAction()
    {
        var bc = new Blockcypher("..", Endpoint.BcyTest);
        await bc.GenerateAddress();
    
        // ..
    }