向WCF添加招摇

向WCF添加招摇,wcf,swagger,Wcf,Swagger,我正试图为微软的WCF制作一个合适的文档。 我添加了一个asp web应用程序来显示swagger并安装了 Swashback.AspNetCore.5.6.3 我已将解决方案设置为同时运行WSF服务和asp web应用程序。 这是我的密码: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Thread

我正试图为微软的WCF制作一个合适的文档。 我添加了一个asp web应用程序来显示swagger并安装了 Swashback.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 /昂首阔步

那里似乎没有任何有效的文档。 有没有办法让招摇成功? 如果你知道另一个更好的选择招摇过市,请随时添加评论。 谢谢

更新:这是我的配置文件的主要部分:

  <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>

Asp.net Core不完全支持WCF,如果Swashback.AspNetCore.5.6.3是AspNetCore中的一个包,则WCF中可能不支持它。事实上,WCF也有自己的帮助文档,您只需在配置文件中启用它:

   <endpointBehaviors>
        <behavior name="ESEndPointBehavior">
            <webHttp helpEnabled="true"/>
        </behavior>
    </endpointBehaviors>


谢谢。我试过了/service1.svc/help未退出。还尝试了service1/help。您的配置文件是什么?这与您的端点地址有关。在服务基址之后添加/help。我发布了我的web.config。你能发布你最后的评论并举例吗?我知道你正在使用basicHttpsBinding,但是帮助文档只针对webhttpbinding。嗨,问题解决了吗?嗨,我尝试了很多方法并更新了上面的配置。它仍然不起作用。如果使用webhttpbinding,还需要将[WebInvoke]添加到操作协议中。有关webhttpbinding的更多信息,可以参考以下链接:嗨,问题解决了吗?如果你认为我的回答对你有帮助,你可以把它标为答案。不,我从来没成功过。