wcf - 向 WCF 添加招摇
问题描述
我正在尝试为 Microsoft WCF 制作适当的好文档。我添加了一个asp web应用程序来显示swagger并安装了Swashbuckle.AspNetCore.5.6.3
我已将解决方案设置为同时运行 WSF 服务和 asp Web 应用程序。这是我的代码:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
namespace asp_core_webapp
{
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.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Version = "1.0", Description = "my api " });
c.DocInclusionPredicate((_, api) => !string.IsNullOrWhiteSpace(api.GroupName));
c.TagActionsBy(api => api.GroupName);
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
services.AddControllers();
services.AddControllers();
// Register the Swagger generator, defining 1 or more Swagger documents
services.AddSwaggerGen();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// 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.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Hello World!");
});
});
}
}
}
我没有看到在 /swagger/v1/swagger.json /swagger/v1 /swagger 上运行任何东西
那里似乎没有任何有效的文档。任何想法如何使招摇工作?如果您知道 Swagger 的另一个更好的替代品,请随时添加评论。谢谢
更新:这是我的配置文件的主要部分:
<system.web>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="serviceBehavior" name="WcfService1.Service1">
<endpoint address="Service1" binding="basicHttpBinding"
bindingConfiguration="" name="serviceEndPoint" contract="WcfService1.IService1" />
<endpoint address="mex" binding="mexHttpBinding"
bindingConfiguration="" name="mex" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="MyEndPointBehavior">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="webHttpBinding" scheme="http" />
</protocolMapping>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true" />
</system.webServer>
解决方案
推荐阅读
- algorithm - Unable to find an appropriate Data Structure for a described scenario
- python - 如何在 django 的 forms.py 文件中使用 django-colorfield?
- javascript - 用回调反应闭包
- microsoft-graph-api - How to get the user's group(s) for sharepoint online site usig Microsoft Graph APIs
- javascript - useEffect stuck on loop when checking props
- python - Adding psycopg2 to setup for dev
- tcl - Can't find path to script being executed by TCL interpreter since info script returns empty string
- reactjs - scrollTop property is not working in react
- django - 如何从 Django(postgreSQL 数据库)进行 groupby 查询
- bash - Bash,杀死 tmux 进程后服务器意外退出