3

ASP.net Web サイトの一部としてではなく、WCF Websocket サービスの一部として SignalR をホストすることは可能ですか。Web サービスから signalR クライアントにメッセージをプッシュすることについては承知していますが、ソケット接続がブラウザーから開かれたときに Web サービス コントラクトにマップされる可能性もありますか?

4

2 に答える 2

5

SignalR サーバーを自己ホストできます。

から取得 ( https://github.com/SignalR/SignalR/wiki/QuickStart-Hubs ):

開始するには、次のパッケージをインストールします。

Install-Package Microsoft.Owin.Hosting -pre
Install-Package Microsoft.Owin.Host.HttpListener -pre
Install-Package Microsoft.AspNet.SignalR.Owin -pre

using System;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin.Hosting;
using Owin;

namespace SignalR.Hosting.Self.Samples
{
class Program
{
    static void Main(string[] args)
    {
        string url = "http://172.0.0.01:8080";

        using (WebApplication.Start<Startup>(url))
        {
            Console.WriteLine("Server running on {0}", url);
            Console.ReadLine();
        }
    }
}

class Startup
{
    public void Configuration(IAppBuilder app)
    {
        // This will map out to http://localhost:8080/signalr by default
        // This means a difference in the client connection.

        app.MapHubs();
    }
}

public class MyHub : Hub
{
    public void Send(string message)
    {
        Clients.All.addMessage(message);
    }
}

}

于 2013-02-11T13:48:50.000 に答える
2

次のような任意の .Net アプリケーションで SignarR ハブをホストできます。

public class Program
{
public static void Main(string[] args)
{
    // Connect to the service
    var hubConnection = new HubConnection("http://localhost/mysite");

    // Create a proxy to the chat service
    var chat = hubConnection.CreateProxy("chat");

    // Print the message when it comes in
    chat.On("addMessage", message => Console.WriteLine(message));

    // Start the connection
    hubConnection.Start().Wait();

    string line = null;
    while((line = Console.ReadLine()) != null)
    {
        // Send a message to the server
        chat.Invoke("Send", line).Wait();
    }
}
}

参照: https://github.com/SignalR/SignalR/wiki/QuickStart-Hubs

WCF を使用する特定の理由がある場合は? サービスは SignarR ハブとしてのみ記述できます。

于 2012-09-24T18:24:55.443 に答える