send message to azure service bus queue with postman

 using System;
 using System.Globalization;
 using System.Security.Cryptography;
 using System.Text;
 using System.Web;

 class MainClass
 {

     static readonly string queueOrTopicUrl = "TODO"; // Format: "https://<service bus namespace>.servicebus.windows.net/<topic name or queue>/messages";
     static readonly string signatureKeyName = "TODO";
     static readonly string signatureKey = "TODO";
     static readonly TimeSpan timeToLive = TimeSpan.FromDays(1);

     public static void Main(string[] args)
     {
         var token = GetSasToken(queueOrTopicUrl, signatureKeyName, signatureKey, timeToLive);
         Console.WriteLine("Authorization: " + token);
     }

     public static string GetSasToken(string resourceUri, string keyName, string key, TimeSpan ttl)
     {
         var expiry = GetExpiry(ttl);
         string stringToSign = HttpUtility.UrlEncode(resourceUri) + "\n" + expiry;
         HMACSHA256 hmac = new HMACSHA256(Encoding.UTF8.GetBytes(key));
         var signature = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(stringToSign)));
         var sasToken = String.Format(CultureInfo.InvariantCulture, "SharedAccessSignature sr={0}&sig={1}&se={2}&skn={3}",
         HttpUtility.UrlEncode(resourceUri), HttpUtility.UrlEncode(signature), expiry, keyName);
         return sasToken;
     }

     private static string GetExpiry(TimeSpan ttl)
     {
         TimeSpan expirySinceEpoch = DateTime.UtcNow - new DateTime(1970, 1, 1) + ttl;
         return Convert.ToString((int)expirySinceEpoch.TotalSeconds);
     }

 }

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source