小编Pra*_*han的帖子

GRPC C# - 众所周知的 grpc 类型存储在哪里以引用它们?无法导入 google.protobuf.Timestamp

我有一个非常简单的 protobuf 文件,如下所示

syntax = "proto3";

option csharp_namespace = "GrpcService1.Protos";

import "google/protobuf/timestamp.proto";
import "Protos/ReportingStatus.proto";

package GrpcService1;

service MetricReportingService {
    rpc ReportMetricData(MetricMessage) returns (StatusMessage);
}
message MetricMessage {
    int32 id = 1;
    int32 value = 2;
    google.protobuf.Timestamp last_updated = 3;
}

message StatusMessage {
    ReportingStatus status = 1;
}

Run Code Online (Sandbox Code Playgroud)

当我构建解决方案时,出现以下错误

1>Protos/MetricProducer.proto(16,9): error : "google.protobuf.TimeStamp" is not defined.
Run Code Online (Sandbox Code Playgroud)

我使用的是 Visual Studio 2019 版本 16.10.0。我添加了 Grpc.aspnetcore 元包。我试图查看众所周知的原型文件是否安装在其他地方,但不确定如何引用众所周知的原型类型。任何帮助将不胜感激。

c# grpc asp.net-core

5
推荐指数
1
解决办法
725
查看次数

创建引用 ActionFilters、HTTPContext 、 HTTPException 等的 .Net 标准库

我在 .Netcore 上编写了一堆 API。我有一些想要在所有 API 中使用的操作属性。我计划创建一个带有操作过滤器的标准库项目,并在所有 API 项目中引用相同的内容。但是,我不确定是否可以添加对 sytem.web 的引用。我收到一堆有关缺少属性的错误,并且无法找到 HTTPConext 和 HTTPException 类型。为 Web API 创建可重用的 actionfilter 属性的正确方法是什么?

c# asp.net class-library asp.net-core

4
推荐指数
1
解决办法
2498
查看次数

Angular Service - 返回的对象类型是object而不是指定的泛型类型

我有一个angular5服务,它执行HTTP get并返回一个特定类型,如下所示

public getProductByIDproductId: string): Observable<Product> {
    const headers = new HttpHeaders({ "Content-Type": "application/json" });
    const url = `${environment.productservice_baseurl}/${productId}`;
    return this.http
      .get<Product>(url, { headers: headers })
      .pipe(       
        tap(data => (this._product = data)),
        catchError(this.handleError)
      );
  }
Run Code Online (Sandbox Code Playgroud)

Product类是一个具有属性和方法的类.下面有一小段摘录.

class Product{
    productID:string;
    productName:string;

    setQuantity(quantity:number){

    }
}
Run Code Online (Sandbox Code Playgroud)

当我在get上返回this._product上调用setQuantity函数时,我得到'setQuantity不是函数'错误.当我尝试检查this._product的实例时,它不是Product类型,而是类型Object.

在get方法上设置的泛型类型是否仅用于帮助编译时类型检查?如何从getProductByIDproductId方法获取产品类的具体实例?

typescript rxjs5 angular angular5

3
推荐指数
1
解决办法
3392
查看次数