如何解决如何使用 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 举报,一经查实,本站将立刻删除。