dee*_*bee 2 c# azure azure-storage-emulator
此处的文档(https://docs.microsoft.com/zh-cn/azure/storage/storage-use-emulator)说,端点应采用以下格式访问模拟表存储:
http://127.0.0.1:10002/<account-name>/<resource-path>
Run Code Online (Sandbox Code Playgroud)
但是,如何从模拟器中获取<account-name>和<resource-path>项目?
有人知道可以连接到仿真器的有效演示吗?我似乎发现的唯一一个连接到Azure。
如果我们要连接到存储模拟器,则代码演示与Azure存储相同。区别在于存储模拟器使用众所周知的帐户名和密钥。
DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;
AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;
Run Code Online (Sandbox Code Playgroud)
要定位存储模拟器,可以使用映射到知名帐户名和密钥的快捷方式。
在这种情况下,您的连接字符串设置为:
<add key="StorageConnectionString" value="UseDevelopmentStorage=true;" />
Run Code Online (Sandbox Code Playgroud)
我们可以从Azure的官方文档中获取代码演示。
// Retrieve the storage account from the connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the table client.
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
// Retrieve a reference to the table.
CloudTable table = tableClient.GetTableReference("people");
// Create the table if it doesn't exist.
table.CreateIfNotExists();
Run Code Online (Sandbox Code Playgroud)
关于如何使用Cosmos模拟器,我们可以从使用Azure Cosmos DB模拟器进行本地开发和测试中获得答案。
我们需要在本地安装Cosmos模拟器。
他的帐户和密钥是唯一允许与Azure Cosmos DB仿真器一起使用的凭据。他们是:
Account name: localhost:<port>
Account key: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
Run Code Online (Sandbox Code Playgroud)
演示代码:
// Connect to the Azure Cosmos DB Emulator running locally
DocumentClient client = new DocumentClient(
new Uri("https://localhost:8081"),
"C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1434 次 |
| 最近记录: |