1
votes

We are using .Net framework 4.6.x and looking for a way to create an azure service bus namespace from the azure.management sdk. We are having trouble implementing programmatically within .Net with C#, Any reference or direct documentation would be helpful. The documentation on msdn seems to utilize the old REST api, we need to upgrade away from this now since windows has done the same. Any direction or references that do not create the service bus in the physical portal or use the REST api.

1
The code.msdn.microsoft.com link is unfortunately dead; it redirects to a set of samples that don't seem to include the sample referenced above.Suman

1 Answers

2
votes

We could use the Azure fluent SDK Microsoft.Azure.Management.Fluent and Microsoft.Azure.Management.ResourceManager.Fluent to do that. I also test it on my side. It works correctly on my side. About how to get the azure credential file, we could refer to Authentication in Azure Management Libraries for .NET I used an authentication file.

subscription=########-####-####-####-############
client=########-####-####-####-############
tenant=########-####-####-####-############
key=XXXXXXXXXXXXXXXX
managementURI=https\://management.core.windows.net/
baseURL=https\://management.azure.com/
authURL=https\://login.windows.net/
graphURL=https\://graph.windows.net/

Demo code.

using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
using Microsoft.Azure.Management.ServiceBus.Fluent;

namespace CreateServiceBus
{
    class Program
    {
        static void Main(string[] args)
        {
            var credentials = SdkContext.AzureCredentialsFactory.FromFile(@"C:\Tom\azureCredential.txt");
            var azure = Azure
                .Configure()
                .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
                .Authenticate(credentials)
                .WithDefaultSubscription();
            var sbNameSpace = "service bus name space";
            var resoureGroup = "resourcegroup";
            var serviceBusNamespace = azure.ServiceBusNamespaces
                .Define(sbNameSpace)
                .WithRegion(Region.USEast)
                .WithNewResourceGroup(resoureGroup)
                .WithSku(NamespaceSku.Basic)
                .Create();

        }
    }
}

enter image description here

Packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.Azure.Management.AppService.Fluent" version="1.0.0" targetFramework="net462" />
  <package id="Microsoft.Azure.Management.Batch.Fluent" version="1.0.0" targetFramework="net462" />
  <package id="Microsoft.Azure.Management.Cdn.Fluent" version="1.0.0" targetFramework="net462" />
  <package id="Microsoft.Azure.Management.Compute.Fluent" version="1.0.0" targetFramework="net462" />
  <package id="Microsoft.Azure.Management.Dns.Fluent" version="1.0.0" targetFramework="net462" />
  <package id="Microsoft.Azure.Management.Fluent" version="1.0.0" targetFramework="net462" />
  <package id="Microsoft.Azure.Management.Graph.RBAC.Fluent" version="1.0.0" targetFramework="net462" />
  <package id="Microsoft.Azure.Management.KeyVault.Fluent" version="1.0.0" targetFramework="net462" />
  <package id="Microsoft.Azure.Management.Network.Fluent" version="1.0.0" targetFramework="net462" />
  <package id="Microsoft.Azure.Management.Redis.Fluent" version="1.0.0" targetFramework="net462" />
  <package id="Microsoft.Azure.Management.ResourceManager.Fluent" version="1.1.3" targetFramework="net462" />
  <package id="Microsoft.Azure.Management.ServiceBus.Fluent" version="1.0.0" targetFramework="net462" />
  <package id="Microsoft.Azure.Management.Sql.Fluent" version="1.0.0" targetFramework="net462" />
  <package id="Microsoft.Azure.Management.Storage.Fluent" version="1.0.0" targetFramework="net462" />
  <package id="Microsoft.Azure.Management.TrafficManager.Fluent" version="1.0.0" targetFramework="net462" />
  <package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.28.3" targetFramework="net462" />
  <package id="Microsoft.Rest.ClientRuntime" version="2.3.8" targetFramework="net462" />
  <package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.8" targetFramework="net462" />
  <package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.3.0" targetFramework="net462" />
  <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net462" />
</packages>