コード例 #1
0
        static internal void CallMethod(
            RcfProtoChannel self,
            Google.ProtocolBuffers.Descriptors.MethodDescriptor method,
            Google.ProtocolBuffers.IRpcController controller,
            Google.ProtocolBuffers.IMessage request,
            Google.ProtocolBuffers.IMessage responsePrototype,
            Action <Google.ProtocolBuffers.IMessage> done)
        {
            self.mResponse      = null;
            self.mResponseError = null;

            self.mDone = done;
            self.mResponsePrototype = responsePrototype;

            // Serialize the request.
            RcfProtoController rcfController = (RcfProtoController)controller;

            if (rcfController != null)
            {
                rcfController.Reset();
                rcfController.mChannel = self;
            }

            string serviceName = method.Service.Name;
            int    methodId    = method.Index;

            byte[] bytes = request.ToByteArray();

            // Hand off to RCF.
            if (self.mSwigCallback == null)
            {
                self.mSwigCallback = new SwigCallback_CallCompletion(self);
            }
            self._CallMethodSwig(serviceName, methodId, bytes, bytes.Length, self.mSwigCallback);

            bool syncRpc = !self.GetAsynchronousRpcMode();

            if (syncRpc)
            {
                if (self.Failed())
                {
                    self.mResponseError = self.ErrorText();
                    throw new System.Exception(self.mResponseError);
                }
            }
        }
コード例 #2
0
        // Entry point from C++.
        static internal void ProtoRpcBegin(
            RcfProtoServer self,
            RcfProtoSession session,
            string serviceName,
            int methodId)
        {
            int requestBufferLen = session._GetRequestBufferLength();

            byte[] requestBuffer = new byte[requestBufferLen];
            session._GetRequestBuffer(requestBuffer, requestBuffer.Length);

            // Look up the service and method.
            Google.ProtocolBuffers.IService service = null;
            if (self.mPbServices.ContainsKey(serviceName))
            {
                service = self.mPbServices[serviceName];
            }

            if (service == null)
            {
                string errorMsg = "The requested service does not exist on this server. Service name: " + serviceName;
                throw new Exception(errorMsg);
            }

            ServiceDescriptor serviceDesc = service.DescriptorForType;
            MethodDescriptor  methodDesc  = serviceDesc.Methods[methodId];

            // Build the request object.
            IMessage   requestPrototype = service.GetRequestPrototype(methodDesc);
            IBuilder   builder          = requestPrototype.WeakCreateBuilderForType();
            ByteString byteString       = ByteString.CopyFrom(requestBuffer);

            builder.WeakMergeFrom(byteString);
            IMessage request = builder.WeakBuild();

            // Call the PB service
            // "=>" not supported in .NET 2.0.
            //Action<IMessage> done = (IMessage msg) => ProtoRpcEndCs(session, msg);
            Action <IMessage> done = delegate(IMessage msg) { ProtoRpcEndCs(self, session, msg); };

            RcfProtoController controller = new RcfProtoController(session);

            service.CallMethod(methodDesc, controller, request, done);
        }