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); }