与ASP.NET网站和一个Web API行动后端共享SignalR枢纽 [英] Sharing SignalR hub with ASP.NET Website and a Web API Mobile Backend
问题描述
我已经设置了SignalR实时通信为我的基于ASP.NET网站。但是,我需要知道,如果有可能有独立行动后端项目,该项目使用相同的服务器和数据库与我们分享同一个SignalR枢纽。基本上就像在同一时间通过网络和移动访问Facebook的收件箱中?
I've set up SignalR Realtime communication for my ASP.NET based website. However, I need to know if it's possible to share the same SignalR Hub with a separate Mobile Backend Project which deals with the same server and database. Basically like accessing the facebook's inbox through web and mobile at the same time?
这将是一个ASP.NET Web项目,并连接到一个集线器移动客户端。
That would be a ASP.NET Web project and a Mobile Client connected to one hub.
推荐答案
如果你想找到的 SignalR Android版,我建议以下工作链路为您启动
If you want to find SignalR for Android, I suggest the following working link for your to start
- SignalR/java-client at GitHub
您可以参考code下面的示例(这是我的问题上SO关于 SignalR Android版:<一href=\"http://stackoverflow.com/questions/31468517/signalr-how-can-i-pass-dynamic-class-to-subscriptionhandler1\">SignalR Android的:我怎么能传递动态类SubscriptionHandler1
You can refer to the following sample code (this is from my question on SO about SignalR for Android: SignalR for Android: how can I pass dynamic class to SubscriptionHandler1
public <T> void startSignalR(String transport, String serverUrl, final String userName, final Class<T> tClass) {
Platform.loadPlatformComponent(new AndroidPlatformComponent());
Credentials credentials = new Credentials() {
@Override
public void prepareRequest(Request request) {
request.addHeader(HEADER_KEY_USERNAME, userName);
}
};
mConnection = new HubConnection(serverUrl);
mConnection.setCredentials(credentials);
mHub = mConnection.createHubProxy(SERVER_HUB_CHAT);
if (transport.equals("ServerSentEvents")) {
mTransport = new ServerSentEventsTransport(mConnection.getLogger());
} else if (transport.equals("LongPolling")) {
mTransport = new LongPollingTransport(mConnection.getLogger());
}
mAwaitConnection = mConnection.start(mTransport);
try {
mAwaitConnection.get();
} catch (InterruptedException e) {
e.printStackTrace();
return;
} catch (ExecutionException e) {
e.printStackTrace();
return;
}
mHub.on("broadcastMessage",
new SubscriptionHandler1<Object>() {
@Override
public void run(final Object msg) {
final String finalMsg;
Gson gson = new Gson();
Object object = gson.fromJson(msg.toString(), tClass);
Field[] fields = object.getClass().getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
try {
System.out.println("Value = " + fields[i].get(object));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
, Object.class);
...
}
希望这有助于!
这篇关于与ASP.NET网站和一个Web API行动后端共享SignalR枢纽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!