示例#1
0
        public Task <HttpResponseMessage> List(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "list")]
            HttpRequestMessage request,
            CancellationToken cancellationToken)
        {
            var jsonSettings = new JsonSerializerSettings
            {
                Formatting       = Formatting.Indented,
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            var serviceInstance = _serviceResolver.GetRegistered();

            var t = serviceInstance.First().ResponseType.GetGenericArguments();

            var directory = new
            {
                Name     = "Service Directory",
                Services = serviceInstance.Select(svc => new
                {
                    Name    = svc.Name,
                    Request = new
                    {
                        Type = svc.RequestType.Name,
                        //Example = Activator.CreateInstance(svc.RequestType)
                    },
                    Response = new
                    {
                        Type = svc.ResponseType.GetGenericArguments()[0].Name,
                        //Example = Activator.CreateInstance(svc.ResponseType, args: new object[] { Activator.CreateInstance(svc.ResponseType.GetGenericArguments()[0]), new ResponseMetaData(svc, ServiceResult.Successful) })
                    },
                    Method = "POST",
                    Url    = $"{Environment.GetEnvironmentVariable("WEBSITE_HOSTNAME")}/api/call/{svc.Name}"
                })
            };

            var responseData = JsonConvert.SerializeObject(directory, jsonSettings);

            var res = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(responseData, Encoding.UTF8, "application/json")
            };

            return(Task.FromResult(res));
        }