Service Stack で Swagger を実装しようとしています。nuget を使用して swagger でサービス スタックをインストールしました。現在の DLL のバージョンは、ほとんどが 3.9.56.0 と報告されています。
私はで提供されている例に従おうとしています... https://github.com/ServiceStack/ServiceStack.UseCases/tree/master/SwaggerHelloWorld
そして、命令はかなりばかげているように見えます...
Plugins.Add(new ServiceStack.Api.Swagger.SwaggerFeature());
nuget を介してインストールした後 (ドキュメントの指示に従って)、「Configure」メソッドに入り、[ApiMember] および [Api] タグを追加し、[Route] タグを変更して概要とメモを追加しました。
しかし、訪問~/swagger-ui/index.html
するとエラーが発生します
Please specify the protocol for ../api
私の api は に~/api
あり、現在 (Hello World) に 1 つのメソッドがあり、~api/Hello/{name}
JSON を返し、正常に動作します。
訪問すると、スタック トレース タイプの出力を含む~api
メッセージが表示されます。Handler for Request not found:
私は何を間違っていますか?Swagger を有効にする手順は非常に単純明快で、詳細な手順が不足しているように見えます。
Esker に対処するための更新...
スタック トレース @ 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
また、「プロトコルを指定してください」は闊歩エラーであり、前述の「検出 URL を変更するテキストボックス」の下の html で画面に表示されます。
ServiceStack.Redisはバージョン3.9.57.0であるため、DLLのバージョンは「ほとんど」同じですが、私はそれを使用していないため、「ほとんど」
更新... 私の解決策
タグ内の web.config ファイルでこれが必要でした。以前はビット<configuration>
を含めていませんでした。<location path="api">
<!-- 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>
また...「ルート」をそのように設定しました...
//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>
しかし、それはswaggerの機能を台無しにしました.
//CORRECT
[Route("/Hello/{name}"...
「api」ビットが削除され、すべてが機能するようになりました。