简体   繁体   English

ASP.NET 内核 Web Api 记录来自外部服务器的事件

[英]ASP.NET Core Web Api log events from an external server

I have a service in ASP.NET Core Web Api that will receive requests from users of a SPA.我在 ASP.NET 核心 Web Api 中有一项服务,它将接收来自 SPA 用户的请求。 Each user is a telephone operator, attached to a branch.每个用户都是电话接线员,隶属于分支机构。 In my application, I use a telephone provider.在我的应用程序中,我使用电话提供商。 This provider makes available some DLLs that are referenced in my project.该提供程序提供了一些在我的项目中引用的 DLL。 For each operator who makes a login request in my application, I need perform a registration with the telephony provider, using the DLLs it makes available for integration.对于在我的应用程序中发出登录请求的每个操作员,我需要使用它为集成提供的 DLL 向电话服务提供商注册。 When registering the operator at the provider, an object of type IInstance is returned with the operator's information.在提供者处注册算子时,会返回一个 IInstance 类型的 object 以及算子的信息。 In this object, I need to register events that will occur for the operator, such as incoming call, the end of a call etc. All of these events are triggered by the phone provider's server and my application needs to listen for these events, and notify the SPA through SignalR.在这个 object 中,我需要注册操作员将发生的事件,例如来电、通话结束等。所有这些事件都由电话提供商的服务器触发,我的应用程序需要监听这些事件,并且通过 SignalR 通知 SPA。

My question is: how to save the IInstance object returned by the provider, with all registered events, for each user who logs in my service?我的问题是:如何为每个登录我的服务的用户保存提供商返回的 IInstance object 以及所有注册事件?

Is it possible to use the session to store these instances?是否可以使用 session 来存储这些实例?

public async Task<IActionResult> Dial(string user)
{
    IInstance instance = _integrationService.Login(user);
    // I need my application to listen to these events, even after the request ends.
    instance.LoggedAgent.IncomingSessionEvent += Agent_IncomingSessionEventHandler
    instance.LogoutEvent += Instance_LogoutEventHandler;

    return Ok();
}

Thanks!谢谢!

Storing Instance of an object in a session, am not sure about that.在 session 中存储 object 的实例,对此我不确定。 I would suggest you rather store the user info in a session and use it to initialize the instance any time you need.我建议您将用户信息存储在 session 中,并在需要时使用它来初始化实例。

If that's not the case, you can serialize the instance into xml and save it in the session or database.如果不是这样,您可以将实例序列化为 xml 并将其保存在 session 或数据库中。 That way you can always de-serialize it to the object instance any time you need it.这样,您可以随时将其反序列化为 object 实例。

I hope it make sense.我希望它有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM