Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • George J. Capnias 1 post 71 karma points
    Jan 23, 2019 @ 16:40
    George J. Capnias
    0

    Using Official Mailjet API v3 .NET Wrapper from Surface controller.

    I have been trying to integrate newsletter capabilities for a customer's web site, using Mailjet API.

    Official Mailjet API v3 .NET Wrapper uses asynchronous functions in order to contact the service. I have a SurfaceController, that gets an Id and tries to retrieve a contact from the Mailjet service.

    In order to use the retrieve method I used something like this:

        public class PageNewsletterFormController : RenderMvcController
    {
        public override ActionResult Index(RenderModel model)
        {
            string ContactID = Request.QueryString["id"];
            ContactModel contact = new ContactModel(model.Content);
    
            string ContactID = Request.QueryString["id"];
            ContactModel contact = new ContactModel(model.Content);
    
            JArray result = null;
    
            MailjetClient client = new MailjetClient(WebConfigurationManager.AppSettings["apiKey"], 
                WebConfigurationManager.AppSettings["apiSecret"]) { Version = ApiVersion.V3_1 };
    
            MailjetRequest request = new MailjetRequest
            {
                Resource = Contact.Resource
            }
            .Filter(Contact.ContactsList, WebConfigurationManager.AppSettings["contactslist"])
            .Filter(Contact.ID, ContactID)
            .Filter(Contact.Limit, "50");
    
            MailjetResponse response = client.GetAsync(request).Result;
    
            return CurrentTemplate(contact);
        }
    

    As soon as the code hits the GetAsync() method the page freezes.

    I tried to do the same with something like this:

        public class PageNewsletterFormController : RenderMvcController
    {
        public async Task<ActionResult> NewsletterForm(RenderModel model)
        {
            string ContactID = Request.QueryString["id"];
            ContactModel contact = new ContactModel(model.Content);
    
            JArray result = null;
    
            MailjetClient client = new MailjetClient(WebConfigurationManager.AppSettings["apiKey"], 
                WebConfigurationManager.AppSettings["apiSecret"]) { Version = ApiVersion.V3_1 };
    
            MailjetRequest request = new MailjetRequest
            {
                Resource = Contact.Resource
            }
            .Filter(Contact.ContactsList, WebConfigurationManager.AppSettings["contactslist"])
            .Filter(Contact.ID, ContactID)
            .Filter(Contact.Limit, "50");
    
            MailjetResponse response = client.GetAsync(request).Result;
    
            return CurrentTemplate(contact);
        }
    

    It has the same problem - it freezes.

    Is there someone that can offer any pointers?

    Thanks, George J.

  • Sotiris Filippidis 274 posts 1395 karma points
    Jan 25, 2019 @ 17:15
    Sotiris Filippidis
    0

    Bump - Having the same problem here (in fact, we're both working on the same project and we're stuck on this). Any advice?

  • Richard Ikegbulam 1 post 71 karma points
    Jan 25, 2019 @ 17:50
    Richard Ikegbulam
    0

    Hi,

    You may have already tried some these...

    I guess you're encountering a deadlock issue here. Looking at the above sample code I can't find an await keyword within an async method.

    Try using the await keyword e.g MailjetResponse response = await client.GetAsync(request);

    (Not the best solution) If within a non async method like i would expect in a SurfaceController (ChildActionOnly) then try calling using this MailjetResponse response = Task.Run(async => await client.GetAsync(request)).GetAwaiter().GetResult();

    Hope it helps. Cheers

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies