Just copy and paste this code to send message to Azure Service Bus queue without the need to install any nugget package like : Azure.Messaging.ServiceBus
Common use case for this is when writing plugins that need to stand alone.
A plugin must be built and compiled into a single DLL.
Prerequisite:
-Azure subscription. To use Azure services, including Azure Service Bus, you need a subscription. If you don't have an existing Azure account, you can sign up for a free trial.
-Visual Studio.
Steps:
-Setup a queue to which you want to send your messages.
-Get the SAS token - a token that is generated from the access key.
-Copy the primary connection string, which contains the service bus namespace URL.
In the code below, I did the following:
Make a normal http request
Specify the service bus namespace url as the base url
Specify queue name as the request uri
Pass the SAS token to the header as “Authorization” property.
Notice how I used an already generated SAS token.
Best practice and in a normal production environment is to do a HMACSHA256 encryption to obtain the SAS token. You will need the SAS policy name, key & URI.
Please repost if you find this useful.