我尝试在Azure函数中使用隔离进程实现Azure SignalR服务。到目前为止,它的工作对我来说还不错。我读了微软的文档,其中提到要注册任何输出绑定,我需要为其创建azure函数。下面是我的代码:
[Function("BroadcastToAll")]
[SignalROutput(HubName = "demohub", ConnectionStringSetting = "AzureSignalRConnectionString")]
public SignalRMessageAction BroadcastToAll([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestData req)
{
try
{
using var bodyReader = new StreamReader(req.Body);
var d = bodyReader.ReadToEnd();
return new SignalRMessageAction("newMessage")
{
// broadcast to all the connected clients without specifying any connection, user or group.
Arguments = new[] { d },
};
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
我的问题是返回类型必须是SignalRMessageAction
。如何让它的返回类型像HttpResponseData
。
1条答案
按热度按时间s4n0splo1#
返回类型必须为
SignalRMessageAction
吗返回类型不一定是
SignalRMessageAction
。我怎么能让它的返回类型像
HttpResponseData
。当我们使用SignalR创建Azure Function时,默认函数代码将使用
HttpResponseData
创建。我的示例代码:
HttpResponseData
。在
local.settings.json
文件中添加SignalRConnectionString。.csproj
文件:*