Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core gRPC没有';似乎无法生成访问服务所需的客户端代码_Asp.net Core_Grpc - Fatal编程技术网

Asp.net core gRPC没有';似乎无法生成访问服务所需的客户端代码

Asp.net core gRPC没有';似乎无法生成访问服务所需的客户端代码,asp.net-core,grpc,Asp.net Core,Grpc,我正在通过从下载并遵循PortfoliosSample探索gRPC。 示例代码都运行良好。然而,当我试图按照示例创建自己的简单服务和客户端时,我注意到客户端生成的代码不包括访问服务所需的类和函数。 在PortfoliosSample中,基于PortfoliosGrpc.cs中的PortfoliosClinet和PortfoliosClinet类生成的客户端代码 下面是生成的TSAPIBrokerGrpc.cs // <auto-generated> // Generated

我正在通过从下载并遵循PortfoliosSample探索gRPC。 示例代码都运行良好。然而,当我试图按照示例创建自己的简单服务和客户端时,我注意到客户端生成的代码不包括访问服务所需的类和函数。 在PortfoliosSample中,基于PortfoliosGrpc.cs中的PortfoliosClinet和PortfoliosClinet类生成的客户端代码

下面是生成的TSAPIBrokerGrpc.cs

// <auto-generated>
//     Generated by the protocol buffer compiler.  DO NOT EDIT!
//     source: TSAPIBroker.proto
// </auto-generated>
#pragma warning disable 0414, 1591
#region Designer generated code

using grpc = global::Grpc.Core;

namespace Test.API.TSAPIBroker.Protos {
  public static partial class GroupService
  {
    static readonly string __ServiceName = "TSAPIBroker.GroupService";

    static readonly grpc::Marshaller<global::Test.API.TSAPIBroker.Protos.GetRequest> __Marshaller_TSAPIBroker_GetRequest = grpc::Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Test.API.TSAPIBroker.Protos.GetRequest.Parser.ParseFrom);
    static readonly grpc::Marshaller<global::Test.API.TSAPIBroker.Protos.GetResponse> __Marshaller_TSAPIBroker_GetResponse = grpc::Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Test.API.TSAPIBroker.Protos.GetResponse.Parser.ParseFrom);

    static readonly grpc::Method<global::Test.API.TSAPIBroker.Protos.GetRequest, global::Test.API.TSAPIBroker.Protos.GetResponse> __Method_Get = new grpc::Method<global::Test.API.TSAPIBroker.Protos.GetRequest, global::Test.API.TSAPIBroker.Protos.GetResponse>(
        grpc::MethodType.Unary,
        __ServiceName,
        "Get",
        __Marshaller_TSAPIBroker_GetRequest,
        __Marshaller_TSAPIBroker_GetResponse);

    /// <summary>Service descriptor</summary>
    public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor
    {
      get { return global::Test.API.TSAPIBroker.Protos.TSAPIBrokerReflection.Descriptor.Services[0]; }
    }

    /// <summary>Base class for server-side implementations of GroupService</summary>
    [grpc::BindServiceMethod(typeof(GroupService), "BindService")]
    public abstract partial class GroupServiceBase
    {
      public virtual global::System.Threading.Tasks.Task<global::Test.API.TSAPIBroker.Protos.GetResponse> Get(global::Test.API.TSAPIBroker.Protos.GetRequest request, grpc::ServerCallContext context)
      {
        throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, ""));
      }

    }

    /// <summary>Creates service definition that can be registered with a server</summary>
    /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
    public static grpc::ServerServiceDefinition BindService(GroupServiceBase serviceImpl)
    {
      return grpc::ServerServiceDefinition.CreateBuilder()
          .AddMethod(__Method_Get, serviceImpl.Get).Build();
    }

    /// <summary>Register service method with a service binder with or without implementation. Useful when customizing the  service binding logic.
    /// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
    /// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
    /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
    public static void BindService(grpc::ServiceBinderBase serviceBinder, GroupServiceBase serviceImpl)
    {
      serviceBinder.AddMethod(__Method_Get, serviceImpl == null ? null : new grpc::UnaryServerMethod<global::Test.API.TSAPIBroker.Protos.GetRequest, global::Test.API.TSAPIBroker.Protos.GetResponse>(serviceImpl.Get));
    }

  }
}
#endregion
//
//由协议缓冲区编译器生成。不要编辑!
//资料来源:TSAPIBroker.proto
// 
#pragma警告禁用04141591
#区域设计器生成的代码
使用grpc=global::grpc.Core;
命名空间Test.API.TSAPIBroker.Protos{
公共静态部分类GroupService
{
静态只读字符串\uuu ServiceName=“TSAPIBroker.GroupService”;
静态只读grpc::Marshaller\uu Marshaller\u TSAPIBroker\u GetRequest=grpc::Marshallers.Create((arg)=>global::Google.Protobuf.MessageExtensions.ToByteArray(arg),global::Test.API.TSAPIBroker.Protos.GetRequest.Parser.ParseFrom);
静态只读grpc::Marshaller\uuu Marshaller\u TSAPIBroker\u GetResponse=grpc::Marshallers.Create((arg)=>global::Google.Protobuf.MessageExtensions.ToByteArray(arg),global::Test.API.TSAPIBroker.Protos.GetResponse.Parser.ParseFrom);
静态只读grpc::Method\uuuu Method\u Get=new grpc::Method(
grpc::MethodType.Unary,
__ServiceName,
“得到”,
__Marshaller_TSAPIBroker_GetRequest,
__Marshaller_TSAPIBroker_GetResponse);
///服务描述符
公共静态全局::Google.Protobuf.Reflection.ServiceDescriptor描述符
{
获取{return global::Test.API.TSAPIBroker.Protos.TSAPIBrokerReflection.Descriptor.Services[0];}
}
///GroupService服务器端实现的基类
[grpc::BindServiceMethod(typeof(GroupService),“BindService”)]
公共抽象部分类GroupServiceBase
{
公共虚拟全局::System.Threading.Tasks.Task Get(全局::Test.API.TSAPIBroker.Protos.GetRequest请求,grpc::ServerCallContext上下文)
{
抛出新的grpc::RpcException(新的grpc::Status(grpc::StatusCode.Unimplemented,“”);
}
}
///创建可以向服务器注册的服务定义
///实现服务器端处理逻辑的对象。
公共静态grpc::ServerServiceDefinition BindService(GroupServiceBase serviceImpl)
{
返回grpc::ServerServiceDefinition.CreateBuilder()
.AddMethod(uu-Method_-Get,serviceinpl.Get).Build();
}
///使用带有或不带实现的服务绑定器注册服务方法。在自定义服务绑定逻辑时非常有用。
///注意:此方法是实验API的一部分,可以在不事先通知的情况下更改或删除。
///服务方法将通过在此对象上调用AddMethod进行绑定。
///实现服务器端处理逻辑的对象。
公共静态void BindService(grpc::ServiceBinderBase serviceBinder,GroupServiceBase serviceImpl)
{
serviceBinder.AddMethod(uuuMethod_Get,serviceImpl==null?null:new grpc::UnaryServerMethod(serviceImpl.Get));
}
}
}
#端区

使用容器映像
mcr.microsoft.com/dotnet/sdk:5.0
,我可以使用您的proto生成两个文件:

  • tsapbroker.cs
  • TSAPIBrokerGrpc.cs
复制:

dotnet新控制台
dotnet添加包Grpc--版本2.33.1
dotnet添加包Grpc.Tools--版本2.33.1
dotnet添加包Google.Api.CommonProtos--版本2.2.0
从项目文件中引用proto,然后生成

我生成的
*Grpc.cs
包含
GroupServiceClient

注意消息
已定义但未使用


感谢DazWilkin的投入!我使用VS.Net 2019的NuGet管理工具将我的Grpc软件包从2.23.2更新到2.33.1,但它没有解决我的问题。然后我注意到我的客户端项目文件包含一行:。将“服务器”更改为“客户端”并重新编译后,我在*Grpc.cs文件中生成了客户端函数。仍然不清楚为什么我必须手动更改GrpcServices值,但我现在可以了。再次感谢。听到这个消息我很高兴!
syntax = "proto3";

option csharp_namespace = "Test.API.TSAPIBroker.Protos";

package TSAPIBroker;

message Group {
    int32 id = 1;
    string name = 2;
}

message Groups {
    repeated Group group = 1;
}

message GetRequest {
    int32 groupId = 1;
}

message GetResponse {
    Group group = 1;
}
service GroupService 
{
    rpc Get(GetRequest) returns (GetResponse);
}
// <auto-generated>
//     Generated by the protocol buffer compiler.  DO NOT EDIT!
//     source: TSAPIBroker.proto
// </auto-generated>
#pragma warning disable 0414, 1591
#region Designer generated code

using grpc = global::Grpc.Core;

namespace Test.API.TSAPIBroker.Protos {
  public static partial class GroupService
  {
    static readonly string __ServiceName = "TSAPIBroker.GroupService";

    static readonly grpc::Marshaller<global::Test.API.TSAPIBroker.Protos.GetRequest> __Marshaller_TSAPIBroker_GetRequest = grpc::Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Test.API.TSAPIBroker.Protos.GetRequest.Parser.ParseFrom);
    static readonly grpc::Marshaller<global::Test.API.TSAPIBroker.Protos.GetResponse> __Marshaller_TSAPIBroker_GetResponse = grpc::Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Test.API.TSAPIBroker.Protos.GetResponse.Parser.ParseFrom);

    static readonly grpc::Method<global::Test.API.TSAPIBroker.Protos.GetRequest, global::Test.API.TSAPIBroker.Protos.GetResponse> __Method_Get = new grpc::Method<global::Test.API.TSAPIBroker.Protos.GetRequest, global::Test.API.TSAPIBroker.Protos.GetResponse>(
        grpc::MethodType.Unary,
        __ServiceName,
        "Get",
        __Marshaller_TSAPIBroker_GetRequest,
        __Marshaller_TSAPIBroker_GetResponse);

    /// <summary>Service descriptor</summary>
    public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor
    {
      get { return global::Test.API.TSAPIBroker.Protos.TSAPIBrokerReflection.Descriptor.Services[0]; }
    }

    /// <summary>Base class for server-side implementations of GroupService</summary>
    [grpc::BindServiceMethod(typeof(GroupService), "BindService")]
    public abstract partial class GroupServiceBase
    {
      public virtual global::System.Threading.Tasks.Task<global::Test.API.TSAPIBroker.Protos.GetResponse> Get(global::Test.API.TSAPIBroker.Protos.GetRequest request, grpc::ServerCallContext context)
      {
        throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, ""));
      }

    }

    /// <summary>Creates service definition that can be registered with a server</summary>
    /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
    public static grpc::ServerServiceDefinition BindService(GroupServiceBase serviceImpl)
    {
      return grpc::ServerServiceDefinition.CreateBuilder()
          .AddMethod(__Method_Get, serviceImpl.Get).Build();
    }

    /// <summary>Register service method with a service binder with or without implementation. Useful when customizing the  service binding logic.
    /// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
    /// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
    /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
    public static void BindService(grpc::ServiceBinderBase serviceBinder, GroupServiceBase serviceImpl)
    {
      serviceBinder.AddMethod(__Method_Get, serviceImpl == null ? null : new grpc::UnaryServerMethod<global::Test.API.TSAPIBroker.Protos.GetRequest, global::Test.API.TSAPIBroker.Protos.GetResponse>(serviceImpl.Get));
    }

  }
}
#endregion