Example #1
0
        private Service CreateServiceRegistration(Type serviceType)
        {
            var methods = new ServiceMethodCollection();
            var messages = new ServiceMessageByIdCollection();

            foreach (var method in serviceType.GetMethods())
            {
                var methodAttributes = method.GetCustomAttributes(typeof(ProtoMethodAttribute), true);

                if (methodAttributes.Length == 0)
                    continue;

                Debug.Assert(methodAttributes.Length == 1);

                var methodAttribute = (ProtoMethodAttribute)methodAttributes[0];

                var serviceMethod = new ServiceMethod(method, methodAttribute, this);

                if (methods.ContainsKey(serviceMethod.Request))
                    throw new ProtoChannelException(String.Format("Invalid service contract '{0}'; multiple ProtoMethod's found for message type '{1}'", serviceType, serviceMethod.Request.Type));

                if (!messages.ContainsKey(serviceMethod.Request.Id))
                    messages.Add(serviceMethod.Request);

                if (serviceMethod.Response != null && !messages.ContainsKey(serviceMethod.Response.Id))
                    messages.Add(serviceMethod.Response);

                methods.Add(serviceMethod);
            }

            if (methods.Count == 0)
                throw new ProtoChannelException(String.Format("Invalid service contract '{0}'; contract does not specify any handlers", serviceType));

            return new Service(serviceType, methods, messages, this);
        }
Example #2
0
        public Service(Type serviceType, ServiceMethodCollection methods, ServiceMessageByIdCollection messagesById, ServiceAssembly serviceAssembly)
        {
            Require.NotNull(serviceType, "serviceType");
            Require.NotNull(methods, "methods");
            Require.NotNull(messagesById, "messagesById");
            Require.NotNull(serviceAssembly, "serviceAssembly");

            Type = serviceType;
            ServiceAssembly = serviceAssembly;
            Methods = methods;
            Messages = messagesById;

            var callbackAttributes = serviceType.GetCustomAttributes(typeof(ProtoCallbackContractAttribute), true);

            if (callbackAttributes.Length > 0)
            {
                Debug.Assert(callbackAttributes.Length == 1);

                CallbackContractType = ((ProtoCallbackContractAttribute)callbackAttributes[0]).Type;
            }
        }