Signalr Hub客户端尝试使用TopicFilter的对象调用Hub的Subscribe方法,该方法在集线器中没有正确地反序列化。 Subsribe中收到的类型是Filter,而我想要TopicFilter对象。如果我使用JsonSerializer类手动序列化和反序列化,但我希望信号器jasonSerilizer这样做,因为如果我必须手动执行,将会有很多地方。有什么想法吗?
hub = connection.CreateHubProxy("DebugDispatcherHub");
hub.JsonSerializer.TypeNameHandling = TypeNameHandling.Auto;
hub.JsonSerializer.TypeNameAssemblyFormat = FormatterAssemblyStyle.Full;
var topicfilter = new TopicFilter() { Topic = new Guid("5D5B26AD-5E6A-4B96-95C8-06540FC17E53") };
hub.Invoke("Subscribe", filter);
public class Filter { }
public class TopicFilter : Filter
{
public Guid Topic { get; set; }
}
[HubName("DebugDispatcherHub")]
public class DebugDispatcherHub : Hub
{
public void Subscribe(Filter filter)
{
//some code here
}
}
internal class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
var service = (Newtonsoft.Json.JsonSerializer)GlobalHost.DependencyResolver.GetService(typeof(Newtonsoft.Json.JsonSerializer));
service.TypeNameHandling = TypeNameHandling.Auto ;
service.TypeNameAssemblyFormat = FormatterAssemblyStyle.Full;
}
}