设为首页 加入收藏

TOP

Ocelot入门实践(二)
2019-09-17 18:34:37 】 浏览:34
Tags:Ocelot 入门 实践
"
//} } }

 打开Program.cs,修改如下:

public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
            .ConfigureAppConfiguration((hostingContext, builder) =>
            {
                builder.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
                .AddJsonFile("ocelot.json", false, true);
            })
            .UseStartup<Startup>();
    }

打开Startup.cs文件,进行如下配置:

public void ConfigureServices(IServiceCollection services)
        {
            services.AddOcelot();//添加Ocelot服务
        }
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseOcelot().Wait();//使用Ocelot服务
        }

Ocelot配置完毕,VS=>调试=>开始执行

打开postman工具进行测试

 

请求 http://localhost:7000/Service1/values

 

请求 http://localhost:7000/Service2/values

 

OK!打完收工

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C#调用C++库知识点 下一篇C# 中数组、ArrayList、List<T..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目