Azure Time Trigger函数报错:目标机器主动拒绝127.0.0.1:10000连接
Azure Time Trigger函数连接127.0.0.1:10000被拒绝问题排查
问题详情
运行Azure Time Trigger函数时触发错误:
"No connection could be made because the target machine actively refused it 127.0.0.1:10000"
函数代码:
public async Task Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, ILogger log) { try { log.LogInformation("C# HTTP trigger function processed a request."); } }
已尝试的操作:
- 清理
%Temp%和Temp文件夹 - 重启计算机
- 确认StorageEmulator处于运行状态
- 修改StorageEmulatorConfig端口为30001/30002/30003
解决方案
1. 同步端口配置到函数连接字符串
修改存储模拟器端口后,必须同步更新项目的local.settings.json文件中的AzureWebJobsStorage连接字符串,将端口替换为修改后的数值:
{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:30001/devstoreaccount1;QueueEndpoint=http://127.0.0.1:30002/devstoreaccount1;TableEndpoint=http://127.0.0.1:30003/devstoreaccount1;", "FUNCTIONS_WORKER_RUNTIME": "dotnet" } }
2. 重置存储模拟器
以管理员身份打开命令提示符,执行以下命令彻底重置模拟器:
AzureStorageEmulator.exe stop AzureStorageEmulator.exe clear all AzureStorageEmulator.exe start
重置后执行AzureStorageEmulator.exe status,确认Blob/Queue/Table服务均处于Running状态。
3. 检查端口占用
使用命令排查10000端口是否被其他进程占用:
netstat -ano | findstr :10000
若有占用,通过任务管理器结束对应PID的进程,再重启模拟器。
4. 替换为Azurite存储模拟器
微软已推荐使用Azurite替代旧版Storage Emulator,步骤如下:
- 通过npm安装:
npm install -g azurite - 启动Azurite:
azurite - 更新
local.settings.json的连接字符串为Azurite默认配置:
"AzureWebJobsStorage": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;"
5. 检查本地防火墙
暂时关闭本地防火墙测试是否解决问题,若可行,添加存储模拟器/Azurite对应端口的入站/出站允许规则。
内容的提问来源于stack exchange,提问作者Vimal Kumar
相关产品推荐
相关产品推荐

