I am new to Azure Signal Services, am trying to get my application hooked to Azure Signal R services. I am doing a proof of concept, to check the feasibility to use in my application.
Code
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCors("CorsPolicy");
app.UseSignalR(routes =>
{
routes.MapHub<NotifyHub>("notify");
});
app.MapAzureSignalR(this.GetType().FullName); ---Error code
app.UseMvc();
}
I am using .NET Core 2.2 and also added the reference to Microsoft.Azure.SignalR.AspNet version 1.0.0-preview1-10317
You need to reference the Microsoft.AspNetCore.SignalR.Http (https://dotnet.myget.org/feed/aspnetcore-ci-dev/package/nuget/Microsoft.AspNetCore.SignalR.Http) package now.
I added a reference to Microsoft.Azure.SignalR and MapAzureSignalR was available in intellisense and it compiled successfuly.
Install-Package Microsoft.Azure.SignalR -Version 1.0.6
Related
I'm using the SoapCore Nuget package to have a soap service on .Net Core. Below is the Configure method from Startup.cs that works great serving a Soap service. My challenge is that I want the service to be used with a service url that includes wildcards in the url path.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Hello World!");
});
});
app.UseSoapEndpoint<IpublishService>("/SoapService.asmx", new SoapEncoderOptions(), SoapSerializer.XmlSerializer);
}
The service works great in Postman using http://localhost:49154/SoapService.asmx but as I mentioned I would like to call it with wildcards like http://localhost:49154/AnyName1/AnyName2/SoapService.asmx
AnyName1 and AnyName2 can be any alpha text.
Thanks in advance for any suggestions.
Hello everyone my name is Taniguchi and i learning asp.net core and I managed to create a migration but when I used the Update-Database command show me the following error: "
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
No migrations configuration type was found in the assembly 'WebApplication1'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).
my database:
public class MimicContext : DbContext
{
public MimicContext(DbContextOptions<MimicContext> options) : base(options)
{
}
public DbSet<Palavra> Palavras { get; set; }
}
my startup:
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<MimicContext>(opt =>
{
opt.UseSqlite("Data Source=Database\\Mimic.db");
});
services.AddMvc(options => options.EnableEndpointRouting = false);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
How can i configure a migration to the assembly ?
Have you enabled migrations in your project? If you didn't than use Enable-Migrations. I think that it could be the problem.
Before running the update command in PMC first enable it. For more details view this link here
Small mistake, but good learning for me after spending more than one day painful effort. I hope this will be the good learning for others too.
I have added two NuGet packages of: EntityFramework, and Microsoft.EntityFrameworkCore which is my mistake.
Just adding NuGet package for Microsoft.EntityFrameworkCore will do all the required work.
I am trying to add the OWIN startup class in a new .Net core class library project. I have installed the package Microsoft.AspNetCore.Owin package. But I still don't see the option to create OWIN Startup class in Add New Items wizard. It used to be there in .Net class library earlier. Is it different in .Net Core class library?
I basically want to create a separate project for my SingalR hub and use it from wherever I want by just referencing it.
This has to do with the tooling of Visual Studio. When you are working on a web project Visual Studio recognizes this and presents web options in the Add New Items Wizard. Since you are working in a class library project Visual Studio does not think you need web based options and thus does not present it. Luckily, the startup class you want is a plain class with some conventions. You should be able to add a class called startup to your class library project and give it the following definition to get what you want:
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace MyClassLibrary
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
}
}
}
Once I've created a ChatHub which derives from Microsoft.AspNetCore.SignalR.Hub<IChatClient>.
All components have been located in separate .net standard library.
IChatClient looks like (it's used for type safety):
public interface IChatClient
{
Task ReceiveChatMessage(string user, string message, DateTime sentAt, bool isMarkedAsImportant);
Task ReceiveChatActivity(string user, Activity activity, DateTime sentAt);
}
Finally I used that ChatHub in an ASP.net core project, where the hub is configured in Startup like this:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseCors(builder =>
{
builder.WithOrigins("https://localhost:3000")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
});
IdentityModelEventSource.ShowPII = true;
}
else
{
app.UseGlobalExceptionHandler();
app.UseHttpsRedirection();
app.NwebSecApiSetup();
}
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHub<ChatHub>("/api/chat");
endpoints.MapHub<EventHub>("/api/events");
});
}
Additionally, I've configured something more for SignalR in the ConfigureServices method:
public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
services.AddControllers().AddControllersAsServices();
services.AddHttpContextAccessor();
services.AddConnections();
services.AddSignalR(options =>
{
options.EnableDetailedErrors = true;
})
.AddNewtonsoftJsonProtocol();
...
}
I suppose you can easily use such Hubs in other projects as well.
I am trying to add Swagger to my ASP.Net Core Web API project, like this:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v0.1", new OpenApiInfo { Title = "My API", Version = "v0.1" });
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
app.UseHttpsRedirection();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v0.1/swagger.json", "My API V1");
});
app.UseRouting();
app.UseAuthorization();
...
}
but I am getting this error:
The type or namespace name 'OpenApiInfo' could not be found
I have installed Swashbuckle.AspNetCore v4.0.1, and my project is .Net Core 3.0.
The reason it is not working is because the type OpenApiInfo comes together with the latest version of Swashbuckle.AspNetCore; open the nuget packages manager, tick the 'include prerelease' checkbox and update the package to version 5.0.0-rc3.
And then it should work.
Add the Latest version of Swashbuckle.AspNetCore package from NuGet Package Manager then it will work.
I'm starting a new project in VS 2015.
File -> New -> Project -> ASP.NET Web Application -> ASP.NET 5 Templates -> Web API
A project is initialized. I would assume that if I run the project with IIS Express a service would be available.
It runs through the startup methods.
public class Startup
{
public Startup(IHostingEnvironment env)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; set; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseIISPlatformHandler();
app.UseStaticFiles();
app.UseMvc();
}
// Entry point for the application.
public static void Main(string[] args) =>
WebApplication.Run<Startup>(args);
}
}
But then it crashes. I don't know how to implement global error handling.
I looked at this example.
But when I try to use System.Net.Http or System.Web.Http.ExceptionHandling they can't be found.
I also noticed that through intellisense it says Core 5.0 is no available.
Here is my project.json as requested.
{
"version":"1.0.0-*",
"compilationOptions":{
"emitEntryPoint":true
},
"dependencies":{
"Microsoft.AspNet.IISPlatformHandler":"1.0.0-rc1-final",
"Microsoft.AspNet.Mvc":"6.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel":"1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles":"1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.FileProviderExtensions":"1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.Json":"1.0.0-rc1-final",
"Microsoft.Extensions.Logging":"1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Console":"1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug":"1.0.0-rc1-final"
},
"commands":{
"web":"Microsoft.AspNet.Server.Kestrel"
},
"frameworks":{
"dnx451":{
"frameworkAssemblies":{
"System.Web":"4.0.0.0"
}
},
"dnxcore50":{
}
},
"exclude":[
"wwwroot",
"node_modules"
],
"publishExclude":[
"**.user",
"**.vspscc"
]
}
Try to open Visual Studio Administrator Mode
I guess it depends on what is crashing - it's not clear from your description what crashes, when it crashes and how it crashes.
You can use UseExceptionHandler and UseDeveloperExceptionPage extension methods to configure an error handling page. This article describes it in more details.
If the exception happens during startup you may need to use UseCaptureStartupErrors extension method (it was recently renamed to CaptureStartupErrors).
Also, you already have logging enabled - the logs may also have some useful information. If you can't see logs because you log to the console consider logging to a file.
If this is IIS/IISExpress crashing check event log.
What is your runtime version ?
Maybe you can try scaffolding your application with the AspNet Yeoman generator and compare the files.
Personally I prefer to use the scaffolder as it is often up to date.
Hope this helps !