My Scenerio is that i need a SignalR self Hosted WCF Service that response and sends message to all connected users that came from Winform or WPF.
I have tried alot as follows:
- I have Created WCF service with SignalR Self Hosting code as below which contains 3 Classes and 1 Interface.
namespace SignalRServiceClass { [ServiceContract] public interface ISignalRServiceClass { [OperationContract] string GetsMessage(string name); [OperationContract] void Configuration(IAppBuilder app); [OperationContract] void Send(string name, string message); } } namespace SignalRServiceClass { public class SignalRServiceClass : ISignalRServiceClass { public string GetsMessage(string name) { return "Message From Service " + name + "!"; } } } namespace SignalRServiceClass { class ClassHub : Hub { public void Send(string name, string message) { Clients.All.addMessage(name, message); } } } namespace SignalRServiceClass { class Startup { public void Configuration(IAppBuilder app) { // app.UseCors(CorsOptions.AllowAll); // app.MapSignalR(); app.Map("/signalr", map => { map.UseCors(CorsOptions.AllowAll); var hubConfiguration= new HubConfiguration { EnableDetailedErrors=true, EnableJSONP= true }; map.RunSignalR(hubConfiguration); }); } } }
And Secondly Winform Client. I am confused here that how to manage the client code here but i put some code for testing as below.
private void button1_Click(object sender, EventArgs e) { //MessageBox.Show(test.GetsMessage("This is the Test Message")); var hubConnection = new HubConnection("http://localhost:50172/"); var serverHub = hubConnection.CreateHubProxy("MessageRecievingHub"); serverHub.On("broadCastToClients", message => MessageBox.Show(message)); hubConnection.Start().Wait(); }
Please guide me in this manner. Your Help will be appreciated. I have tried and googled alot but in vain.
Thanks alot in Advance.