如何在 Bond 服务定义中实现功能?

How do I implement functions in a Bond services definition?

查看 Bond Comm documentation,我不清楚我为服务定义的函数如何连接到我的代码中的特定函数。

它是否在项目中查找具有相同签名的函数并将其分配给端点?是否缺少某些基础设置文件?

注意:Bond Comm 已弃用。它不再受支持,并将在即将发布的版本中从 Bond 中删除。 Bond-over-gRPC 是它的替代品。

使用 Bond-over-gRPC 或 Bond Comm 时,生成的服务器端代码是一个抽象 class,服务定义中的每个方法都有一个抽象方法。要为这些方法提供逻辑,您需要从生成的基础继承并为所有服务方法提供实现。然后,通常在您的 main 函数中,您创建一个服务器(用于 Bond-over-gRPC)或一个监听器(用于 Bond Comm)并注册一个实现实例 class。这为您的实现代码设置了 IDL 服务方法的路由。

来自Bond-over-gRPC C# documentation

Given a service definition like the following:

service Example
{
    ExampleResponse ExampleMethod(ExampleRequest);
}

gbc will generate C# classes for gRPC with the --grpc flag:

gbc c# --grpc example.bond

...

To build the service functionality, simply write a concrete service implementation by subclassing the server base and supplying the business logic:

public class ExampleServiceImpl : Example.ExampleBase {
    public override async Task<IMessage<ExampleResponse>>
        ExampleMethod(
            IMessage<ExampleRequest> param,
            ServerCallContext context)
    {
        ExampleRequest request = param.Payload.Deserialize();
        var response = new ExampleResponse();

        // Service business logic goes here

        return Message.From(response);
    }
}

This service implementation is hooked up to a gRPC server as follows:

var server = new Grpc.Core.Server {
    Services = { Example.BindService(new ExampleServiceImpl()) },
    Ports = { new Grpc.Core.ServerPort(ExampleHost, ExamplePort, Grpc.Core.ServerCredentials.Insecure) } };
server.Start();

At this point the server is ready to receive requests and route them to the service implementation.

还有更多例子:

值得指出的是,(Bond-over-) gRPC 和 Bond Comm 既不是 SOAP 也不是 REST。这个问题被标记为 ,有时人们在谈论 Web 服务时指的是 SOAP/REST。我认为 gRPC 和 Bond Comm 都是基于 TCP 的自定义二进制协议,尽管 gRPC 在 HTTP/2.

之上 运行