有没有办法从.Net内创建一个azure服务总线命名空间?

时间:2018-01-04 22:55:38

标签: c# .net azure azureservicebus

我们正在使用.Net framework 4.6.x并寻找一种从azure.management sdk创建azure服务总线命名空间的方法。我们无法使用C#在.Net中以编程方式实现,任何参考或直接文档都会有所帮助。 msdn上的文档似乎使用了旧的REST api,我们现在需要升级,因为windows已经完成了相同的操作。任何不在物理门户中创建服务总线或使用REST API的方向或引用。

1 个答案:

答案 0 :(得分:1)

我们可以使用Azure流畅的SDK Microsoft.Azure.Management.Fluent  和Microsoft.Azure.Management.ResourceManager.Fluent这样做。我也在我身边测试它。它在我身边正常工作。关于如何获取azure凭证文件,我们可以参考Authentication in Azure Management Libraries for .NET 我使用了身份验证文件。

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/

演示代码。

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>