Grpc+MagicOnion的学习和例子(二)
一,继续上一篇博客的扩展( Grpc+MagicOnion的学习和例子(一)),我们再服务端加入MagicOnion.Hosting包,如下
把startup的配置注释调,我们再program添加主机配置,如下
program
using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Runtime.Loader; using System.Threading.Tasks; using Grpc.Core; using MagicOnion.Hosting; using MagicOnion.Server; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace grpcDemo { public class Program { public static void Main(string[] args) { CreateHostBuilder(args) .UseMagicOnion( ///程序集配置,其他都是一样的 new[] { AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName("Service")) }, new MagicOnionOptions(isReturnExceptionStackTraceInErrorDetail: true), new ServerPort("localhost", 6000, ServerCredentials.Insecure) ) .Build() .Run(); } public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }); } }
二,运行看结果,调试成功