无法连接到windows 2012 r2和.net core 1.0.1中的Azure表存储
我最近将asp.net核心项目从rc2版本升级到1.0.1。我很难弄清楚如何连接到Azure表存储。好像有什么东西挡住了我的联系 请注意,这段代码在我的本地开发环境Win10 15063上运行。它在运行Win2012R2的开发服务器上不工作。它还与.net core预览版本1.0.0-preview2-003133一起使用,但与.net core最终版本1.0.1不一起使用 我正在使用最新的Azure存储包8.1.1 这是我的密码无法连接到windows 2012 r2和.net core 1.0.1中的Azure表存储,azure,azure-storage,azure-table-storage,Azure,Azure Storage,Azure Table Storage,我最近将asp.net核心项目从rc2版本升级到1.0.1。我很难弄清楚如何连接到Azure表存储。好像有什么东西挡住了我的联系 请注意,这段代码在我的本地开发环境Win10 15063上运行。它在运行Win2012R2的开发服务器上不工作。它还与.net core预览版本1.0.0-preview2-003133一起使用,但与.net core最终版本1.0.1不一起使用 我正在使用最新的Azure存储包8.1.1 这是我的密码 var azureTableStorageConnectionS
var azureTableStorageConnectionString = "DefaultEndpointsProtocol=https;AccountName=blah_blahstoragedev;AccountKey=Blahblah;EndpointSuffix=core.windows.net"; //Configuration["AzureStorageConnectionString"];
storageAccount = CloudStorageAccount.Parse(connectionString);
tableClient = storageAccount.CreateCloudTableClient();
buildTable = tableClient.GetTableReference(BuildTableName);
buildTable.CreateIfNotExists();
它因以下异常而失败:
Microsoft.WindowsAzure.Storage.StorageException:“无法连接到远程服务器”
InnerException{无法建立连接,因为目标计算机主动拒绝了它127.0.0.1:8888}System.Exception{System.Net.Sockets.SocketException}
StackTrace在
Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T]RESTCommand`1
cmd,IRetryPolicy策略,OperationContext OperationContext
在
Microsoft.WindowsAzure.Storage.Table.TableOperation.ExecuteCloudTableClient
客户端、CloudTable表、TableRequestOptions请求选项、,
操作上下文操作上下文
在
Microsoft.WindowsAzure.Storage.Table.CloudTable.ExistsBoolean
primaryOnly、TableRequestOptions、requestOptions、OperationContext
操作上下文
在
Microsoft.WindowsAzure.Storage.Table.CloudTable.CreateIfNotExistsTableRequestOptions
请求选项,操作上下文操作上下文
我在安装了.NET Core 1.0.1的Windows Server 2012 R2上测试了以下代码,在我这方面效果很好
public async static void CreateTable(string tableName)
{
var connectionString = "my connection string";
var storageAccount = CloudStorageAccount.Parse(connectionString);
var tableClient = storageAccount.CreateCloudTableClient();
Microsoft.WindowsAzure.Storage.Table.CloudTable buildTable = tableClient.GetTableReference(tableName);
await buildTable.CreateIfNotExistsAsync();
Console.WriteLine("Create success");
}
您的代码和我的代码的区别在于,在构建应用程序时,我不能使用CreateIfNotExists方法。我给我看了下面的错误。因此,我使用CreateIfNotExistsAsync方法代替
错误CS1061:“CloudTable”不包含“CreateIfNotExists”的定义,并且找不到接受“CloudTable”类型的第一个参数的扩展方法“CreateIfNotExists”
请使用异步方法并再次测试代码。下面是GitHub中与之相关的讨论
我们的NetCore/Netstandard支持还不包括API的同步实现
目标机器主动拒绝127.0.0.1:8888
8888通常用作代理或防病毒软件的端口。请确定创建表请求是否被防火墙或防病毒软件阻止。我建议您使用工具(例如Wireshark)检查网络数据包是否已成功从您的服务器发送。以下是我使用Fiddler捕获的.NET Core 1.0.1和Azure Storage SDK创建新表时从Windows Server 2012 R2发送的请求
POST https://mystroagename.table.core.windows.net/Tables() HTTP/1.1
Connection: Keep-Alive
Content-Type: application/json
Accept: application/json; odata=minimalmetadata
Accept-Charset: UTF-8
Authorization: SharedKey mystroagename:mykey
User-Agent: Azure-Storage/8.1.1 (.NET Core)
MaxDataServiceVersion: 3.0;NetFx
Prefer: return-no-content
DataServiceVersion: 3.0;
x-ms-client-request-id: 5eeb6570-0ca0-42c7-844a-6acdcc3b7bb9
x-ms-version: 2016-05-31
x-ms-date: Mon, 03 Apr 2017 07:26:43 GMT
Content-Length: 23
Host: mystroagename.table.core.windows.net
{"TableName":"newtablename"}
防火墙?存储模拟器是否在本地运行?嘿,可能涉及防火墙,但肯定没有本地存储在运行。但是,我确实指定了连接字符串。他们应该连接到我的连接字符串所说的,对吗?嗯,上面说127.0.0.1拒绝连接,所以你做错了。嗨,谢谢你尝试。让我试试。亲爱的,谢谢你的帮助。结果是defaultproxy有一个entry machine.config,指向127.0.0.0:8888。不知何故,新的.net内核尊重这一点,并将我的呼叫重定向到127.0.0.0:8888