Exemplo n.º 1
0
        //同步方法
        public RpcResult <HelloRes> SayHelloAgain(HelloReq req)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(10006, 2);

            message.FriendlyServiceName = "Greeter.SayHelloAgain";


            message.Data = req.ToByteArray();
            var response = base.CallInvoker.BlockingCall(message);

            if (response == null)
            {
                throw new RpcException("error,response is null !");
            }
            var result = new RpcResult <HelloRes>();

            if (response.Code != 0)
            {
                result.Code = response.Code;
            }
            else if (response.Data == null)
            {
                result.Code = ErrorCodes.CODE_INTERNAL_ERROR;
            }
            else
            {
                result.Data = HelloRes.Parser.ParseFrom(response.Data);
            }
            return(result);
        }
Exemplo n.º 2
0
        public async Task <RpcResult <HelloRes> > SayHelloAsync(HelloReq req, int timeOut = 3000)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(10006, 1);

            message.FriendlyServiceName = "Greeter.SayHello";
            message.Data = req.ToByteArray();
            var response = await base.CallInvoker.AsyncCall(message, timeOut);

            if (response == null)
            {
                throw new RpcException("error,response is null !");
            }
            var result = new RpcResult <HelloRes>();

            if (response.Code != 0)
            {
                result.Code = response.Code;
            }
            else if (response.Data == null)
            {
                result.Code = ErrorCodes.CODE_INTERNAL_ERROR;
            }
            else
            {
                result.Data = HelloRes.Parser.ParseFrom(response.Data);
            }

            return(result);
        }
Exemplo n.º 3
0
//同步方法
        public HelloRes SayHelloAgain(HelloReq request)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(10006, 2);

            message.Data = request.ToByteArray();
            var response = base.CallInvoker.BlockingCall(message);

            if (response == null)
            {
                throw new RpcException("error,response is null !");
            }
            if (response.Data == null)
            {
                return(new HelloRes());
            }
            return(HelloRes.Parser.ParseFrom(response.Data));
        }
Exemplo n.º 4
0
        public async Task <HelloRes> SayHelloAgainAsync(HelloReq request, int timeOut = 3000)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(10006, 2);

            message.Data = request.ToByteArray();
            var response = await base.CallInvoker.AsyncCall(message, timeOut);

            if (response == null)
            {
                throw new RpcException("error,response is null !");
            }
            if (response.Data == null)
            {
                return(new HelloRes());
            }
            return(HelloRes.Parser.ParseFrom(response.Data));
        }