Home > Net >  WebApi SignalR published together in the console
WebApi SignalR published together in the console

Time:10-10

Recently in do about WebApi, SignalR test (just contact),
Has been successful in asp.net webapi project joined the SignalR, can deploy using IIS,
Then want to deploy in the console procedures, the results met the problem,


1, create a console program
2, Nuget introduced "Microsoft. AspNet. WebApi. SelfHost"
3, add Controller Controller
4, in the Program. To write the following code cs:

Class Program
{
The static void Main (string [] args)
{

//WebApi SelfHost
Var config=new HttpSelfHostConfiguration (" http://localhost:22 ");

The config. Routes. MapHttpRoute (
"API Default", "API/{controller}/{id}",
New {id=RouteParameter. Optional});

Using (HttpSelfHostServer server=new HttpSelfHostServer (config))
{
Server. OpenAsync (). Wait ();
Console. WriteLine (" Press Enter to quit. ");
The Console. ReadLine ();
}
}
}


5, thus achieve the goal of transfer WebApi from IIS to the console program,
6, next, want to SignalR add
7, Nuget introduction: "Microsoft. AspNet. SignalR"

8, add a MessageHub class, inheritance Hub abstract class
9, add a Startup class

[assembly: OwinStartup (typeof (SelfHost. SignalR. Startup))]

The namespace SelfHost. SignalR
{
Public class Startup
{
Public void Configuration (IAppBuilder app)
{
//detailed information on how to configure the application, please visit https://go.microsoft.com/fwlink/? LinkID=316888
App. MapSignalR ();
////app. UseCors ();
////cross-domain support
//app. UseCors (CorsOptions. AllowAll);
//app. RunSignalR<> (a);
//app. UseSignalR (routes=& gt;
//{
//routes. MapHub (" signalrHubs ");
//});

//the message bus - Hub Hub configuration
App. The Map ("/MessageHub ", the Map=& gt;
{
//SignalR allow cross-domain call
Map. UseCors (CorsOptions. AllowAll);
HubConfiguration config=new HubConfiguration ()
{
//disable JavaScript proxy
EnableJavaScriptProxies=false,
//enabled the json cross-domain
EnableJSONP=true,
//feedback the result to the client
EnableDetailedErrors=true
};
Map. RunSignalR (config);
});

//WebApi allow cross-domain call
App. UseCors (CorsOptions. AllowAll);
}
}
}

10, the follow-up should be how to operate? If is Signalr separate deployment to the console, by introducing the Signalr. SelfHost, use the WebApp. Start (string url) way,

O guide

CodePudding user response:

Actually no one reply

CodePudding user response:

reference rookie commander of the 1st floor response:
actually nobody reply ah
the original poster you solve this problem now?
  •  Tags:  
  • C#
  • Related