【问题标题】:How to add protobuf in ServiceStack如何在 ServiceStack 中添加 protobuf
【发布时间】:2023-03-29 14:30:01
【问题描述】:

我正在尝试将 protobuf 添加到基于 ServiceStack 的 Web 项目中。但是以下两种方法都会出错

Global.asax.cs

 public AppHost() : base("My Service", typeof (HelloService).Assembly)
    {
       ServiceStack.Plugins.ProtoBuf.AppStart.Start();


    }
 public AppHost() : base("My Service", typeof (HelloService).Assembly)
    {

       Plugins.Add(new ProtoBufFormat());

    }

如何在项目中启用 ProtoBuf 格式?

【问题讨论】:

    标签: c# servicestack protobuf-net


    【解决方案1】:

    由于您没有提及遇到了什么错误,请首先确保您已添加 ServiceStack ProtoBuf NuGet Package

    然后添加ProtoBufFormat 插件就是您需要做的所有事情,但所有配置都包括在内。 ServiceStack 插件的注册必须使用您的 AppHost.Configure() 方法进行,因此请尝试:

    public class AppHost
    {
       ...
    
       public void Configure(Container container)
       {
           Plugins.Add(new ProtoBufFormat());
       }
    }
    

    【讨论】:

    • 我通过将 webactivator 框架添加到项目中以某种方式解决了这个问题,因为较新的 ServiceStack.Plugins.Protobuf 删除了它;我使用较旧的 ServiceStack.Plugins.Protobuf 版本 @mythz 将其添加回来
    • @jeff 由于它是 1-less 依赖项,我更喜欢自己避免使用 WebActivator,无论哪种方式,您只需要在启动时使用 new AppHost().Init(); 初始化 ServiceStack,无论是在 Global.asax/Application_Start 中还是使用 WebActivator。跨度>
    • 我不知道为什么当我使用最新的 ServiceStack.Plugins.Protobuf 时 Plugins.Add(new ProtoBufFormat()) 或 ServiceStack.Plugins.ProtoBuf.AppStart.Start() 无法解决依赖关系。
    • @jeff Plugins.Add(new ProtoBufFormat());在 AppHost.Configure 中,而不是在构造函数中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-30
    • 2011-11-16
    • 1970-01-01
    相关资源
    最近更新 更多