我们正在使用 .Net Framework 4.6.x,并寻找一种从 azure.management sdk 创建 azure 服务总线命名空间的方法。我们在使用 C# 在 .Net 中以编程方式实现时遇到困难,任何引用或直接文档都会有所帮助。 msdn 上的文档似乎使用旧的 REST api,我们现在需要升级它,因为 Windows 也做了同样的事情。不在物理门户中创建服务总线或使用 REST API 的任何指示或引用。
最佳答案
我们可以使用 Azure Fluent 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();
}
}
}
包.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>
关于c# - 有没有办法从 .Net 中创建 azure 服务总线命名空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48104773/