问题描述
我们正在使用.Net framework 4.6.x,正在寻找一种从azure.management sdk创建azure服务总线名称空间的方法。我们在使用C#在.Net中以编程方式实现时遇到了麻烦,任何参考或直接文档都将有所帮助。 msdn上的文档似乎利用了旧的REST api,由于Windows已执行相同的操作,因此我们现在需要升级。不会在物理门户中创建服务总线或使用REST API的任何方向或参考。
我们可以使用Azure流畅的SDK
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版本= 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>
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.
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 .NETI 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();
}
}
}
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>
这篇关于有什么方法可以从.Net内部创建Azure Service Bus命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!