Microsoft.Azure.NotificationHub - Async call in sync method
<p>I currently have to provide a sync as async method in my API: Please find the code below. The only problem is that I don’t have a
sync method in the backend. I use Azure.NotificationHub client. That client has only *Async methods. Is my way reasonable?</p>

<pre><code>    public PushHubNotificationResult SendPushMessage(string userId, string message)
    {
        PushHubNotificationResult result = new PushHubNotificationResult(); 
        try
        {
            result = SendPushMessageAsync(userId, message).GetAwaiter().GetResult();

        } catch (Exception ex)
        {
            result.Status = PushHubNotificationResultType.Error;
            result.Error = ex.Message;
            result.Exception = ex;
        }

        return result;
    }

    public async Task&lt;PushHubNotificationResult&gt; SendPushMessageAsync(string userId, string message)
    {
        PushHubNotificationResult result = new PushHubNotificationResult();

        // EnableTestSend see: https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-push-notification-fixer/#self-diagnose-tips

        // Create a new Notification Hub client.
        Microsoft.Azure.NotificationHubs.NotificationHubClient hub =
            Microsoft.Azure.NotificationHubs.NotificationHubClient.CreateClientFromConnectionString(NotificationHub, NotificationHubName);

        // Sending the message so that all template registrations that contain "messageParam"
        // will receive the notifications. This includes APNS, GCM, WNS, and MPNS template registrations.
        Dictionary&lt;string, string&gt; templateParams = new Dictionary&lt;string, string&gt;();

        templateParams["messageParam"] = message;

        string userTag = "_UserId:" + userId; // That line sets the IMEI or SerialNo (WLAN only device) == userId to which the push message is sent

        try
        {
            // Send the push notification and log the results.
            NotificationOutcome outcome = await hub.SendTemplateNotificationAsync(templateParams, userTag);

            result.Status = PushHubNotificationResultType.Success;

            foreach (RegistrationResult hubResult in outcome.Results)
            {
                result.PushNotificationHub = hubResult.ApplicationPlatform;
                result.RegistrationId = hubResult.RegistrationId;
                result.Outcome = hubResult.Outcome;
            }

        }
        catch (System.Exception ex)
        {
            result.Status = PushHubNotificationResultType.Error;
            result.Error = ex.Message;
            result.Exception = ex;
        }

        return result;
    }
</code></pre>

<p>thanks for any advice,
Eric</p>