2017-01-17 6 views
3

私はweb APIとswagger UIを統合するのに問題がありますが、何か問題がありません。私は従うC#web api swagger integration

[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")] 

namespace dummyNamespace 
{ 
    public class SwaggerConfig 
    { 
     public static void Register() 
     { 
     var thisAssembly = typeof(SwaggerConfig).Assembly; 
     GlobalConfiguration.Configuration 
      .EnableSwagger(c => c.SingleApiVersion("v1", "Test API")) 
      .EnableSwaggerUi(); 

     } 
    } 
    } 

私は、ブラウザで闊歩を呼び出して、ページhttp://localhost:56381/swagger/ui/indexは、私はこのコードを持っているSwaggerConfig.csで

http://localhost:56381/swagger/ui/index

はファイルこのスクリーンショットのようなものですこのチュートリアル:http://www.wmpratt.com/swagger-and-asp-net-web-api-part-1/しかし、働いていない。

私の設定で何が間違っているのでしょうか?

私は、.NET Framework 4.5.2、Web APIを2.0とSwashbuckle.5.5.3バージョンを使用

アップデート: 私はこのイメージこのURLに

http://localhost:56381/swagger/docs/v1 

リターンを呼び出すとき: docs/v1

更新1:

このコードをWebApiConfig.csに入れた後:

var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml"); 
     config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType); 

http://localhost:56381/swagger/ui/indexリターンこのJSON:

{ 
    "statusCode": 200 
    } 

どれIDEEがどのようにhttp://localhost:56381/swagger/ui/indexリターンこのページを作るようにする:enter image description here

enter image description here

ページには、テストプロジェクトからです。

+0

なぜあなたはそれを信じますか? – MrBlue

+1

リンクをクリックしてみてください;それはpngファイルです。リンクはpng – MrBlue

+0

の説明です@MegaTron My Startup.csは私のプロジェクトのルートにあります。 'code' public partial classスタートアップ { public voidコンフィグレーション(IAppBuilderアプリケーション) { ConfigureAuth(app); } } – MrBlue

答えて

1

あなたが投稿したチュートリアルを読んだ後に、あなたのルートURLがどういうわけかswaggerが期待しているものと異なるかもしれないように見えます。闊歩設定ファイルから:

// By default, the service root url is inferred from the request used to access the docs. // However, there may be situations (e.g. proxy and load-balanced environments) where this does not // resolve correctly. You can workaround this by providing your own code to determine the root URL. // //c.RootUrl(req => GetRootUrlFromAppConfig());

が一致しない場合は、それがインストールnuget swashbuckleが何らかの形で破損している可能性があります。ナゲットパッケージを取り出して再インストールしてください。