Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gRpc transcoding is not working- unable to find annotation.proto and http.proto are thrown #1965

Closed
VenkateshSrini opened this issue Nov 26, 2022 · 9 comments
Labels
question Further information is requested

Comments

@VenkateshSrini
Copy link

I'm trying to do gRpc Transcoding with .NET 7. I'm following the article here. I'm also referring to the sample implementation here. Ater I added the proto files (annotation.proto and http.proto) and include the annotations.proto to main proto file. I get the error
Rebuild started... 1>------ Rebuild All started: Project: CacheService, Configuration: Debug Any CPU ------ Restored C:\CarryCase\Venkatesh\M2c\grpc\net7\CacheService\CacheService.csproj (in 40 ms). 1>google/api/annotations.proto : error : File not found. 1>Protos/cache.proto(2,1): error : Import "google/api/annotations.proto" was not found or had errors. 1>Done building project "CacheService.csproj" -- FAILED. ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ========== ========== Elapsed 00:00.428 ==========

The code is attached herewith. I have already referred to similar solutions at this link and this link . But still the issue is not resolved
net7.zip

@VenkateshSrini VenkateshSrini added the question Further information is requested label Nov 26, 2022
@JamesNK
Copy link
Member

JamesNK commented Nov 29, 2022

Either move the Protos/google folder to google (i.e. the root of your project) or change the imports to Protos/google/api/annotations.proto

@VenkateshSrini
Copy link
Author

@JamesNK ,
I have done the solution that you suggested that is to add Protos/google/api/annotation. I'm still getting similar errors. the error message is as below

Rebuild started...
1>------ Rebuild All started: Project: CacheService, Configuration: Debug Any CPU ------
Restored C:\CarryCase\Venkatesh\M2c\grpc\net7\CacheService\CacheService.csproj (in 58 ms).
1>Protos/google/api/http.proto(344,5): error : "CustomHttpPattern" is not defined.
1>Protos/google/api/annotations.proto(19,1): error : Import "Protos/google/api/http.proto" was not found or had errors.
1>Protos/google/api/annotations.proto(30,3): error : "HttpRule" is not defined.
1>Protos/cache.proto(2,1): error : Import "Protos/google/api/annotations.proto" was not found or had errors.
1>Done building project "CacheService.csproj" -- FAILED.

========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

========== Elapsed 00:00.687 ==========
I'm attaching the same code with this issue (net7.zip). It would be of immense help if you can fix
the same code and upload the same to the response. I would use it as a sample for my upcoming projects.
net7.zip

@VenkateshSrini
Copy link
Author

@JamesNK did you get time to check the code I shared? Can you please help with this?

@JamesNK
Copy link
Member

JamesNK commented Dec 1, 2022

I got it working after some changes.

I changed the import in cache.proto:

import "Protos/google/api/annotations.proto";

And I change the import in annotations.proto:

import "Protos/google/api/http.proto";

And for some reason your http.proto was missing the message definition for CustomHttpPattern:

// A custom pattern is used for defining custom HTTP verb.
message CustomHttpPattern {
  // The name of this custom HTTP verb.
  string kind = 1;

  // The path matched by this custom verb.
  string path = 2;
}

I'm guessing there was a mistake when copying the file from https://github.com/dotnet/aspnetcore/blob/33e2bca8af250a5e9d31060cbe14bbbda23ce3a7/src/Grpc/JsonTranscoding/test/testassets/Sandbox/google/api/http.proto#L369-L376

@VenkateshSrini
Copy link
Author

@JamesNK Thanks you very much. I have one more small doubt. When I have to share the proto files with the client then Should I send the protos folder fully as Zip file as the includes are also there? My second doubt is when generating the client should I remove the rest endpoints definition in proto or it will just be ignored

@JamesNK
Copy link
Member

JamesNK commented Dec 1, 2022

It's ignored.

@VenkateshSrini
Copy link
Author

VenkateshSrini commented Dec 1, 2022

@JamesNK Thank you for your quick response. I'm planning to deploy this in Kubernetes. Does that mean the gRPC request will communicate in one port and grpc-transcoding will communicate in another? The gRpc communication port is specified below in Program.cs below
`builder.WebHost.ConfigureKestrel(webOptions =>
{

webOptions.ListenAnyIP(5275, kestrelOptions =>
{
    kestrelOptions.Protocols = Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http2;
});

});`

similarly is there an option for me to specify the port where the transcoding will work?

Should I change the above definition also to use Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http1AndHttp2? I want to avoid SSL negotiation issues

Do I need to expose two different ports in the Kubernetes pod so that both gRpc transcoding and gRPC service work? My intention is that all the in-cluster communication should be in gRPC and all external communication (outside the cluster via LB or node port) should be through gRpc Transcoding

@JamesNK
Copy link
Member

JamesNK commented Dec 1, 2022

Does that mean the gRPC request will communicate in one port and grpc-transcoding will communicate in another?

It is up to you. If you are ok with calling RESTful JSON methods over prenegotiated HTTP/2 then you can reuse one port for both.

Or add one that is Http1 only if you want to use HTTP/1.1.

@VenkateshSrini
Copy link
Author

@JamesNK . Thanks you for your help. I have completed the sample and is available at. Please let me know your feedbacks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants