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

Add support for grpc service host, support grpc, rest, built-in rpc remote call #366

Open
fanliang11 opened this issue Oct 21, 2019 · 1 comment

Comments

@fanliang11
Copy link
Owner

add interface ,Set the default value of the ServerCallContext parameter to null. see code

using Greet;
using Grpc.Core;
using Surging.Core.CPlatform.Ioc;
using Surging.Core.CPlatform.Runtime.Server.Implementation.ServiceDiscovery.Attributes;
using System.Threading.Tasks;

namespace Surging.IModuleServices.Common
{
    [ServiceBundle("api/{Service}/{Method}")]
    public  interface IGreeterService : IServiceKey
    {
        Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context=null);
    }
}

add GreeterBehavior, see code

using Greet;
using Surging.Core.CPlatform.Ioc;

namespace Surging.Modules.Common.GreeterServices
{
    public  partial class GreeterBehavior : Greeter.GreeterBase,IServiceBehavior
    {
        
    }
}

Add business module,see code

using Greet;
using Grpc.Core;
using Surging.IModuleServices.Common;
using Surging.Modules.Common.GreeterServices;

using System.Threading.Tasks;

namespace Surging.Modules.Common.Domain
{
    public class GreeterService: GreeterBehavior, IGreeterService
    {
        public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
        {
            return Task.FromResult(new HelloReply
            {
                Message = "Hello " + request.Name
            });
        }
    }
}

test rest call
图片
test grpc call
图片

@fanliang11
Copy link
Owner Author

client grpc test code:

using Greet;
using Grpc.Core;
using System;

namespace GrpcService1
{
    public class Program
    {
        public static void Main(string[] args)
        {
           var  channel = new Channel("127.0.0.1", 95, ChannelCredentials.Insecure);
           var client = new Greeter.GreeterClient(channel);
            var result = client.SayHello(new HelloRequest
            {
                Name = "fanly"
            });

            Console.WriteLine("grpc Client Call SayHello():" + result); 
            Console.ReadKey();
        } 
    }
}

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

No branches or pull requests

1 participant