使用 C++ 的协议缓冲区客户端和 C# 后端?

发布于 2024-09-05 14:59:55 字数 48 浏览 1 评论 0 原文

如何通过 HTTP 或等效的 Web 服务将 C# 后端与 C++ 前端连接起来?

How do you connect C# back-end with a C++ front-end via HTTP or web-service equivalent?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剑心龙吟 2024-09-12 14:59:55

这里分为三个部分;服务器(听起来像 C#)、客户端(听起来像 C++)和传输。将它们分开,并从最重要的开始:

  • 传输:这里的重大决定是您希望数据采用什么形状。您提到了协议缓冲区,所以我们正在谈论二进制 - 但这可能是:

    • 原始八位字节流(想想:从网络服务器下载图像)
    • 返回流或字节[]的 SOAP Web 服务
    • 返回 MTOM 的同一个 SOAP Web 服务

    任何都应该有效;选择哪个取决于可用的工具。重要的是:通过网络获取一大块二进制文件。

    此时您还需要考虑数据定义; .proto 文件 可以定义您的架构以及大多数协议缓冲区实现包括一个生成匹配类的工具。

  • 服务器:根据上面的选择,这将是一个处理程序 (IHttpHandler) 或一个 Web 服务类。不管怎样,他们的工作实际上是运行一些逻辑并返回字节流。如何获取数据取决于您,最终的工作是
    填充 DTO 类型(在许多情况下从 .proto 生成,但并非严格必需)并通过序列化 API 运行它,将结果写入
  • 客户端的流:反之亦然;从 .proto 生成 DTO,并通过反序列化 API 运行它

列出了各种 protobuf 实现(C++、C# 等)此处

There are three parts here; the server (sounds like C#), the client (sounds like C++) and the transport. Taking them separately, and starting with the most important:

  • the transport: big decision here is what shape you want the data to be in. You mention protocol buffers, so we're talking binary - but that could be:

    • a raw octet-stream (think: downloading an image from a web-server)
    • a SOAP web-service returning a stream or byte[]
    • the same SOAP web-service returning MTOM

    Any should work; which to choose depends on the tools available. The important thing is : get a chunk of binary over the wire.

    You also need to think about the data definition at this point; a .proto file can define your schema, and most protocol buffers implementations include a tool to generate matching classes.

  • the server: depending on the choice above, this is either going to be a handler (IHttpHandler) or a web-service class. Either way, their job is really to run some logic and return a byte stream. How you get your data is up to you, then ultimately the job is to
    populate the DTO types (generated from .proto in many cases, but not strictly necessary) and run it through the serialization API, writing the result to the stream
  • the client: same in reverse; generate your DTOs from the .proto, and run it through the deserialization API

The various protobuf implementations (C++, C#, etc) are listed here.

陌上芳菲 2024-09-12 14:59:55

C++ 通过您选择的形式(Web 服务和其他)的 HTTP 请求访问后端的公开部分。

The C++ accesses the exposed parts of the back-end via HTTP-Requests in which form you choose (webservice and others).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文