简体   繁体   中英

how to using the method future but Dart grpc client not give unknown service after call the future methods

I have an issue to run this service in my client but when I console.log before the request it was fine

here is the code:

import 'package:grpc/grpc.dart';
import 'package:rpc/src/generated/blog.pb.dart';
import 'package:rpc/src/generated/blog.pbgrpc.dart';

Future<void> main() async  {
  final channel = ClientChannel(
    'localhost',
    port: 50051,
    options: const ChannelOptions(credentials: ChannelCredentials.insecure()),
  );

  var stub = BlogServiceClient(channel);
  // final name = args.isNotEmpty ? args[0] : 'world';

  try {
    var bg = Blog();
    bg.authorId  = "name";
    bg.title = "LOL";
    bg.content = "Content here";
    var data = CreateBlogRequest();
    data.blog = bg;
    print(data);
     await stub.createBlog(data);
//    print(gotIt.);
  } catch (er) {
    print('something error yeahh ===> $er');
  }

  await channel.shutdown();
}

blog.proto ::

syntax = "proto3";

package blog;
//option go_package="blogpb";

message Blog {
    string id = 1;
    string author_id = 2;
    string title = 3;
    string content = 4;
}

message CreateBlogRequest {
    Blog blog = 1;
}

message CreateBlogResponse {
    Blog blog = 1;
}

message ReadBlogRequest {
    string blog_id = 1;
}

message ReadBlogResponse {
    Blog blog = 1;
}

message UpdateBlogRequest {
    Blog blog = 1;
}

message UpdateBlogResponse {
    Blog blog = 1;
}

service BlogService {
    rpc CreateBlog (CreateBlogRequest) returns (CreateBlogResponse);
    rpc ReadBlog (ReadBlogRequest) returns (ReadBlogResponse);
    rpc UpdateBlog (UpdateBlogRequest) returns (UpdateBlogResponse);
}

what I got is gRPC Error (12, unknown service blog.BlogService) I think I already change port and command options also, but still doesn't work and the same result

what I expect it I create the blog with that service createBlog

i run the server on Go

I really need to know this badly what's wrong, I think dart developer not too many because it hards for me to find info about this out on the internet there, so I came here to ask, and hope grpc Dart team will help some developers about some issues, I have seen on the GitHub issue on grpc-dart, not many the team answer some issues on grpc-dart

i gave wrong package name on .proto file

it was not same like service BlogService {}

my package name was named package something , after i changed tp package blog it was work well

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM