【问题标题】:How do I view my Swagger docs when using SwaggerWcf?使用 SwaggerWcf 时如何查看我的 Swagger 文档?
【发布时间】:2019-06-23 01:51:50
【问题描述】:

我正在尝试使用 swaggerwcf 将 Swagger 添加到我的 WCF REST API。

我已按照说明进行操作,但我不知道使用哪个 URL 来查看我的 Swagger 文档。我试过了:

http://myservername/api-docs

http://myservername/api-docs/index.html

http://myservername/api-docs/swagger.json

这些都导致“请求错误”,“服务器在处理请求时遇到错误。请参阅服务帮助页面以构造对服务的有效请求。”

【问题讨论】:

    标签: wcf swagger swagger-wcf


    【解决方案1】:

    这取决于您在 global.asax 中编写的代码。

    比如我在global.asax中的代码是

      protected void Application_Start(object sender, EventArgs e)
        {
            RouteTable.Routes.Add(new ServiceRoute("RegistrationService/api-docs", new WebServiceHostFactory(), typeof(SwaggerWcfEndpoint)));
        }
    

    那我应该访问http://localhost:62193/RegistrationService/api-docshttp://localhost:62193是我的根路径)。

    另外,请确保您已配置 web.xml。

      <service name="SwaggerWcf.SwaggerWcfEndpoint">
        <endpoint address="" binding="webHttpBinding" contract="SwaggerWcf.ISwaggerWcfEndpoint"></endpoint>
      </service>
    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
     <system.webServer>
    
    
    <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
    

    然后如果你输入http://localhost:62193/RegistrationService/api-docs/,它会将你重定向到http://localhost:62193/RegistrationService/api-docs/index.html?url=/RegistrationService/api-docs/swagger.json#!/Books/Service_BookStore_ReadBooks

    下面是结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-26
      • 2014-03-08
      • 1970-01-01
      • 1970-01-01
      • 2021-01-31
      相关资源
      最近更新 更多