如何在Visual Studio代码中调试Azure Function应用和SignalR服务

问题描述

我在Azure中有一个Azure SignalR服务资源,该资源正在无服务器模式下运行。

与此相呼应的是使用TypeScript在Visual Studio Code中构建的Azure Functions应用。

我有一个使用InfoRTrigger的名为Info的功能。该功能将通过调用名为“ Info”的方法来触发。

组成此功能代码为:

function.json

{
  "bindings": [
    {
      "type": "signalRTrigger","name": "inv","hubName": "mailBox","category": "messages","event": "Info","connectionStringSetting": "AzureSignalRConnectionString","parameterNames":[
        "mailBoxInfo"
      ],"direction": "in"      
    },{
      "type": "http","direction": "out","name": "res"
    }
  ],"scriptFile": "../dist/Info/index.js"
}

脚本-index.js

import { AzureFunction,Context,HttpRequest } from "@azure/functions"

const httpTrigger: AzureFunction = async function (context: Context,invocation:any,res: HttpRequest): Promise<void> {

    context.res = {
        // status: 200,/* Defaults to 200 */
        body: 'boom'
    };

};

export default httpTrigger;

我的问题是:

如何调试使用SignalRTrigger输入绑定的功能

如果我在VS Code Azure Functions扩展中使用“立即执行函数”选项,则会遇到以下错误

不确定这是否与整个问题有关?

[2020-11-10T20:19:57.884Z] Executing 'Functions.Info' (Reason='This function was programmatically 
        called via the host APIs.',Id=1d7cc8c0-d49d-4ff4-bc1b-38fa92a3de2e)
[2020-11-10T20:19:57.887Z] Executed 'Functions.Info' (Failed,Id=1d7cc8c0-d49d-4ff4-bc1b-38fa92a3de2e,Duration=4ms)
[2020-11-10T20:19:57.887Z] System.Private.CoreLib: Exception while executing function: 
         Functions.Info. Microsoft.Azure.WebJobs.Host: Exception binding 
         parameter 'invocation'. Microsoft.Azure.WebJobs.Host: Object 
         reference not set to an instance of an object.

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)