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.
Related
I'm newbie in GraphQL for .NET core.
I Added GraphQL in my source but it not into controller when debug. It went to my ObjectGrapType
See the image detail :
Click start in GrapiQL
enter image description here
Then It not go to controller
enter image description here
3.It go to the Order Query
enter image description here
I don't understand why it happens
Can't you help me check that.
Is that an error or not?
My startUp class :
public void ConfigureServices(IServiceCollection services)
{
services.AddDiscoveryClient(Configuration);
services.AddCustomDbContext(Configuration);
services.AddControllers()
.AddNewtonsoftJson(o => o.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
services.AddMediatR(typeof(Startup).GetTypeInfo().Assembly);
services.AddCustomSwagger();
services.AddCustomDependency(Configuration);
}
// 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.UseDiscoveryClient();
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
app.UseGraphiQl("/graphql");
app.UseRouting();
app.UseAuthorization();
app.UseGraphQL<OrderQuerySchema>();
app.UseGraphQLPlayground(options: new GraphQLPlaygroundOptions());
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
Thanks very much and have a good day
LamNV
Didn't get it. what lib do you use - GraphQL.Net?
Btw, based on GraphQL.net is existed a more elegant solution that allows starting much easier. You just have to define schemas in JSON file and set DB-connection string (NReco.GraphQL)
Can I use Swashbuckle to generate Swagger UI from project with Blazor C#
I know that swaschbuckle requires MVC and that you cannot have both of them in same project.
But is there any way around it.
I have resolved the issue by using the Balzor template for W ASP.Net core 3.0 application. And following this guide:Getting started with swashbuckle ASP.Net Core 3.0
I have used pre-release version 5.0.0-rc3 of Swashbuckle since version 4.0.1 failed at startup.
My startaup for anyone facing the same issue:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// 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.AddControllers();
// Register the Swagger generator, defining 1 or more Swagger documents
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
});
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
services.AddSingleton<WeatherForecastService>();
}
// 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.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
}
Swagger is basically to expose your APIs on UI and if there is API controller concept then yes you can definitely use the swagger for blazor APIs....
Please go through the below URL and I am pretty sure that it will help you get what you want..
If you still facing any issue then please let me know I will try to give you an practical example of this...
https://www.talkingdotnet.com/create-a-crud-app-using-blazor-and-asp-net-core/
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
Ive managed to enable Cors fine and my client application communications to my web API application using AJAX. The problem is its open to any host now. I added the following line to Startup.Auth.cs:
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
I was using the standard WebApi method for cors, but had problems when issuing token authentication.
My question is how do i restrict origins using this method?
You can restrict the origin using CorsPolicyBuilder Class
app.UseCors(builder =>
builder.WithOrigins("http://localhost", "https://localhost"));
Define one or more named CORS policies, and then select the policy by name at run time
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy("AllowSpecificOrigin",
builder => builder.WithOrigins("http://example.com"));
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
...
// Shows UseCors with named policy.
app.UseCors("AllowSpecificOrigin");
...
}
You can read how to define CORS at here.
I have .Net Core application with angular 2 cli. I am trying to call my controller action from the different port, I know that I can use CORS to make that work, but it is not working. has anyone the idea what could be the problem? thank you!
Your current configuration is allowing the wrong origin (HTTPS and not HTTP).
//Optional - called before the Configure method by the runtime
public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseCors(builder =>
{
builder.WithOrigins("http://localhost:4200")
.AllowAnyMethod()
.AllowAnyHeader();
});
)
}