如何使用 Azure SignalR 服务将消息从 ASP.NET Web 窗体应用程序发送到 Azure 函数?

问题描述

我已经创建了一些简单的 Azure 函数并创建了一个 signalR。

这是服务器代码

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Microsoft.Azure.WebJobs.Extensions.Signalrservice;

namespace TaskOnesignalrservice
{
    public static class Functions
    {
        [FunctionName("negotiate")]
        // used to send the url and the SAS token that will be used by the client to connect to the signalR service 
        public static SignalRConnectionInfo GetSignalRInfo(
            [HttpTrigger(AuthorizationLevel.Anonymous,"post")] HttpRequest req,[SignalRConnectionInfo(HubName = "signalRHub")] SignalRConnectionInfo connectionInfo,ILogger log) // injection of signal R 
        {
            // when we send an htpp request we will have the signalR address to access it 
            log.Loginformation("Running Connection:" + connectionInfo.Url + " " + connectionInfo.Accesstoken);
            return connectionInfo; // the resourse 
        }

        // Receives a chat message in the request body and uses the SignalR output binding to broadcast the message to all connected client applications.
        [FunctionName("broadcast")]
        public static Task SendMessage(
            [HttpTrigger(AuthorizationLevel.Anonymous,"post")] object message,[SignalR(HubName = "signalRHub")] IAsyncCollector<SignalRMessage> signalRMessages,ILogger log)//binding the signalR message 
        {
            log.Loginformation("Message:" + message.ToString());
            
            return signalRMessages.AddAsync(
                new SignalRMessage
                {
                    Target = "newMessage",//target all 
                    Arguments = new[] { message } // we add the message in the arguments of the output of signalR
                });
        }
    }
}

但现在我想知道在客户端添加什么,它是一个简单的文本栏和按钮来发送消息。

这是 ASP.NET Web 窗体应用程序中的按钮和文本代码

private void button1_Click(object sender,EventArgs e)
{
}

我可以在这里添加什么?

解决方法

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

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

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