我正在尝试使用招摇wcf https://github.com/abelsilva/swaggerwcf/将 Swagger 添加到我的 WCF REST API。
我已按照说明操作,但不知道使用哪个 URL 来查看我的 Swagger 文档。我试过了:
http://myservername/api-docs http://myservername/api-docs
http://myservername/api-docs/index.html http://myservername/api-docs/index.html
http://myservername/api-docs/swagger.json http://myservername/api-docs/swagger.json
这些都会导致“请求错误”、“服务器在处理请求时遇到错误。请参阅服务帮助页面以构建对服务的有效请求。”
这取决于您在 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-docs http://localhost:62193/RegistrationService/api-docs (http://本地主机:62193 http://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/,它会将您重定向到http://localhost:62193/RegistrationService/api-docs/index.html?url=/RegistrationService/api-docs/swagger.json#!/Books/Service_BookStore_ReadBooks http://localhost:62193/RegistrationService/api-docs/index.html?url=/RegistrationService/api-docs/swagger.json#!/Books/Service_BookStore_ReadBooks
Below is the result.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)