Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
226 views
in Technique[技术] by (71.8m points)

c# - Is there any way to create a azure service bus namespace from within .Net?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:TomazureCredential.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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...