Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR Client - IHubProxy.On<> and Invoke<> accepting an interface

Tags:

c#

signalr

I am building a windows service that will act as a client to an existing site that's employing SignalR.

I have IHubProxy.On<> and IHubProxy.Invoke methods working when passing around concrete classes.

For example, this works:

 hubProxy.On<MigrationRequest>("iSWindowsServiceRequest", request =>
     MigrateData.Invoke(request));

And the MigrationRequest looks like this:

public class MigrationRequest : IISWindowsServiceRequest
{
    public MigrateWhat What { get; set; }
    public MigrationFor For { get; set; }
    public Guid EntityFor_Id { get; set; }
}

Now, If i try this:

hubProxy.On<IISWindowsServiceRequest>("iSWindowsServiceRequest", request => 
Handshake.HandleRequest(request));

my request is never picked up.

what I was hoping to achieve was creating single pub-sub methods, rather than one for each concrete class that this service would accept.

Is it possible to pass in an interface into the On<>() methods?

The same goes for the Invoke<>() - if the object I am passing contains any properties that are of an interface, the call never makes it.

so this will not work:

public class ISWindowsServiceResponse
{
    public IISWindowsServiceRequest OriginalRequest { get; set; }
    public bool Success { get; set; }
    public string Message { get; set; }
}

but this will

public class ISWindowsServiceResponse
{
    public MigrationRequest OriginalRequest { get; set; }
    public bool Success { get; set; }
    public string Message { get; set; }
}
like image 521
Darren Wainwright Avatar asked Jul 08 '15 17:07

Darren Wainwright


1 Answers

Where I work, we spent a lot of time trying to figure out a way to get SignalR hubs to serialize interfaces. In the end, we wound up having to extract real objects (real classes and structs, not behind an interface) to send over the wire. There is no way to tell SignalR how to serialize an interface.

like image 93
Grace Avatar answered Oct 06 '22 08:10

Grace