招摇着服务栈不工作 [英] Swagger with Service Stack not working

查看:285
本文介绍了招摇着服务栈不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图实现与服务栈扬鞭。我已经安装使用的NuGet招摇服务栈。 。当前的DLL版本报告为3.9.56.0大多

I am trying to implement Swagger with Service Stack. I've installed service stack with swagger using nuget. Current DLL versions are reported as 3.9.56.0 mostly.

我想效仿的榜样......在提供
https://github.com/ServiceStack/ServiceStack.UseCases/tree/master/SwaggerHelloWorld

I am trying to follow the example provided at... https://github.com/ServiceStack/ServiceStack.UseCases/tree/master/SwaggerHelloWorld

和instrucstion出现相当防呆...

and the instrucstion appear fairly fool-proof...

Plugins.Add(new ServiceStack.Api.Swagger.SwaggerFeature());



进入配置的方法我已经通过的NuGet安装后(如文档指示)然后,我已经添加[ApiMember]和[API]标签,以更改[路线]标签一起添加摘要及附注

goes into the 'Configure' method after I've installed via nuget (as the documentation instructs), then I've added [ApiMember] and [Api] tags, along with changes to the [Route] tags to add Summary and Notes

但是当我访问〜/招摇的UI / index.html的我得到的错误

but when I visit ~/swagger-ui/index.html i get the error

Please specify the protocol for ../api

我的API坐镇〜/ API ,我目前所面对的(世界您好)坐在一个方法〜API /您好/ {名} 返回JSON和工程确定。

My api sits at ~/api, and I have a single method at the moment (Hello World) sitting at ~api/Hello/{name} which returns JSON and works ok.

如果我访问〜API 我得到处理程序的请求未找到的消息:与堆栈跟踪类型的输出。

if I visit ~apii get the message Handler for Request not found: with a stack trace type output.

我在做什么错了?说明启用招摇真的出现直线前进,并详细说明似乎欠缺,可能是因为它应该只是工作',请大家帮忙!

What am I doing wrong? The instructions to enable swagger appear really straight forward, and detailed instructions appear to be lacking, probably because it should 'just work', please help!

更新解决的Esker ...

Update to address Esker...

堆栈跟踪@为myhost:54011 / API

Stack trace @ myhost:54011/api

Handler for Request not found: 


Request.ApplicationPath: /
Request.CurrentExecutionFilePath: /api
Request.FilePath: /api
Request.HttpMethod: GET
Request.MapPath('~'): D:\Starteam\Private\user\web\ServiceStackSwagger\ServiceStackSwagger\
Request.Path: /api
Request.PathInfo: 
Request.ResolvedPathInfo: /api
Request.PhysicalPath: D:\Starteam\Private\user\web\ServiceStackSwagger\ServiceStackSwagger\api
Request.PhysicalApplicationPath: D:\Starteam\Private\user\web\ServiceStackSwagger\ServiceStackSwagger\
Request.QueryString: 
Request.RawUrl: /api
Request.Url.AbsoluteUri: http://localhost:54011/api
Request.Url.AbsolutePath: /api
Request.Url.Fragment: 
Request.Url.Host: localhost
Request.Url.LocalPath: /api
Request.Url.Port: 54011
Request.Url.Query: 
Request.Url.Scheme: http
Request.Url.Segments: System.String[]
App.IsIntegratedPipeline: True
App.WebHostPhysicalPath: D:\Starteam\Private\user\web\ServiceStackSwagger\ServiceStackSwagger
App.WebHostRootFileNames: [global.asax,global.asax.cs,helloservice.cs,jquery-1.10.2.js,packages.config,servicestackswagger.csproj,servicestackswagger.csproj.user,web.config,web.debug.config,web.release.config,app_data,app_start,bin,controllers,dto,models,obj,properties,swagger-ui,views]
App.DefaultHandler: metadata
App.DebugLastHandlerArgs: GET|/api|D:\Starteam\Private\user\web\ServiceStackSwagger\ServiceStackSwagger\api

此外,请指定协议是一个招摇的错误,显示屏幕上在上述下面HTML文本框更改发现网址

Also, "Please specify protocol' is a swagger error, displayed onscreen in html underneath the aforementioned 'textbox to change discovery url'

和DLL的版本是大多是'一样,因为ServiceStack.Redis为3.9.57.0版本,但我没有使用,因此主要是

and the DLL versions are 'mostly' the same because ServiceStack.Redis is version 3.9.57.0, but I'm not using that, so 'mostly'

更新...我的解决方案

Update... My Solution

我需要这在我的web.config文件里面的<结构> 标签,我以前不包括<位置路径=API方式>

I needed this in my web.config file inside of the <configuration> tag, I had previously not included the <location path="api"> bit.

<!-- ServiceStack: CustomPath /api -->
<location path="api">
    <system.web>
      <httpHandlers>
        <add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
      </httpHandlers>
    </system.web>

    <!-- Required for IIS 7.0 -->
    <system.webServer>
      <modules runAllManagedModulesForAllRequests="true"/>
      <validation validateIntegratedModeConfiguration="false" />
      <handlers>
        <add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
      </handlers>
    </system.webServer>
  </location>



也......我已经建立了我的'路线'这样...

also... I had set up my 'routes' as such...

//INCORRECT
[Route("/api/Hello/{name}", Summary = @"N031'5 ServiceStackSwagger thingy", Notes = "Some more info in here cause these are notes")]    
    public class Hello : IReturn<HelloResponse>



但与招摇的功能混乱,它需要是...

but that messed with swagger's functionality, it needed to be...

//CORRECT   
[Route("/Hello/{name}"...

与API位​​,清除了,现在一切工作。

with the 'api' bit REMOVED, and now everything is working.

推荐答案

您需要告诉扬鞭有关ServiceStack扬鞭端点的具体网址,而不是你的服务的基础URL。此端点位于 /资源在你的基础URL。因此,而不是 ../ API 的的 discoveryUrl ,使用 ../ API /资源,像这样,在你的index.html文件:

You need to tell Swagger about the specific URL of the ServiceStack Swagger endpoint, rather than the base URL of your services. This endpoint is located at /resources under your base URL. So, instead of ../api for the discoveryUrl, use ../api/resources, like so, in your index.html file:

window.swaggerUi = new SwaggerUi({
    discoveryUrl: '../api/resources',
    ...

这篇关于招摇着服务栈不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆