[英]How do i config the WCF Service Running URL as SignalR url?
I am Developing a Real Time Application.I am Created a ASP.NET MVC Client Application and WCF Service.and Again i need to add the signalR concept in WCF and Client side for real time notification. 我正在开发一个实时应用程序。我创建了一个ASP.NET MVC客户端应用程序和WCF Service。再次,我需要在WCF和客户端添加signalR概念以进行实时通知。
For this i am created an self hosted signalR and added this solution to WCF Service Solution in visual Studio. 为此,我创建了一个自托管的signalR并将此解决方案添加到visual Studio中的WCF服务解决方案。
My WCF Service Running URL Address is : http://localhost:63694/Service1.svc 我的WCF服务运行URL地址是: http:// localhost:63694 / Service1.svc
My Requirement is WCF and SignalR work together.and the CLient is ASp.Net MVC4 我的要求是WCF和SignalR一起工作.CLient是ASp.Net MVC4
The WCF and ASP.NET MVC codes are here WCF和ASP.NET MVC代码在这里
SignalR code:- SignalR代码:-
namespace SelfHostingSignalR
{
class Program
{
static void Main(string[] args)
{
try
{
string url = "http://localhost:63694/Signalr";
using (WebApp.Start(url))
{
Console.WriteLine("Server running on {0}", url);
Console.ReadLine();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
}
}
}
class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
app.MapSignalR();
}
}
public class MyHub : Hub
{
public void Send(string user)
{
Clients.All.addMessage(user);
}
}
}
For signalr url i am hardcoded some value with wcf url address: 对于signaler url,我使用wcf url地址对一些值进行了硬编码:
string url = " http://localhost:63694/Signalr "; 字符串url =“ http:// localhost:63694 / Signalr ”;
i don't know is it correct or not.Could anyone provide me a solution to solve this? 我不知道它是否正确。有人可以给我解决方案吗?
how do i configure the WCF Service Running Url to signalR url? 如何将WCF服务运行网址配置为signalR url?
To self-host SignalR on a WCF web service application, you just need to configure /signalr
in Startup.cs
: 要在WCF Web服务应用程序上自托管SignalR,只需在
Startup.cs
配置/signalr
:
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
app.MapSignalR();
}
}
with MyHub defined like this: MyHub定义如下:
public class MyHub : Hub
{
public void Send(string user)
{
Clients.All.addMessage(user);
}
}
in your client MVC .NET application, you can invoke server method and define client method as below: 在客户端MVC .NET应用程序中,您可以调用服务器方法并定义客户端方法,如下所示:
[HttpGet]
public async Task<ActionResult> SignalR()
{
dynamic model = new ExpandoObject();
using(var hubConnection = new HubConnection("http://localhost:63694"))
{
var myHub = hubConnection.CreateHubProxy("MyHub");
myHub.On<string>("addMessage", (user) =>
{
model.User = user;
});
await hubConnection.Start();
await myHub.Invoke("Send", "an user");
}
return View(model);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.