【发布时间】:2021-04-16 01:09:45
【问题描述】:
我正在尝试为 Microsoft WCF 制作合适的文档。 我添加了一个 asp web 应用程序来显示招摇并安装 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 /招摇/v1 /大摇大摆
那里似乎没有任何有效的文档。 任何想法如何使招摇工作? 如果您知道 Swagger 的另一个更好的替代品,请随时添加 cmets。 谢谢
更新:这是我的配置文件的主要部分:
<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>
【问题讨论】:
-
您好,问题解决了吗?
-
嗨,我尝试了很多东西并更新了上面的配置。它仍然无法正常工作。
-
如果使用webhttpbinding,还需要在操作协议中添加【WebInvoke】。更多关于webhttpbinding的信息可以参考这个链接:docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/…
-
您好,问题解决了吗?如果您觉得我的回复对您有帮助,可以标记为回答。
-
何。不,我从来没有成功过。